He who stops being better stops being good. -Peter
Submit your own quote
  • home
  • about
  • lab
  • work
  • contact

Tiny Form Class

I created this form class for a project I was doing that used multiple fields. Now let's face it, making a variable for over 30 fields is just rediculous. This simple form class is meant to simplify your life! You can make as many fields as you want in your HTML and have them either emailed to you or inserted into your database.

 

Download it!

 

Here's how to use it.

So you've got your HTML form (on a .php page) that looks like this:

 

PLAIN TEXT
HTML:
<form method="post">
 First Name: <input type="text" name="firstname" /> <br/>
 Last Name: <input type="text" name="lastname" /> <br/>
 Phone: <input type="text" name="phone" /> <br/>
 <input type="submit" name="send" value="Send It!" /> 
 </form>

 

Sending as Email

 

If you're going to be using this to email your data then you will want to add this snippet of PHP code.

 

PLAIN TEXT
PHP:
include("form.class.php");

if(isset($_POST['send'])){

    // This method will send all your data to an email in a table based layout.
    $form = new Form();
    $form->type('email'); // Type of submission
    $form->subject('Contact Form'); // Subject of the email.
    $form->sendTo('your@email.com'); // Who to send the data to.
    $form->submitBtn('send'); // Name field on the submit input.
    $form->send(); // EXECUTE!

}

 

Sending to Database


If you will be using the class for inserting the data into your database, then use this snippet of PHP code. You must make sure that each input name in your HTML is the same as the field name in your database. Example: <input type="text" name="firstname" /> is your HTML, you must have the fieldname 'firstname' in your database so it knows where to put the data.

 

PLAIN TEXT
PHP:
include("form.class.php");

if(isset($_POST['send'])){

    $form = new Form();
    $form->type('database'); // Type of submission.
    $form->dbtable('tablename'); // Name of the table in the database.
    $form->submitBtn('send'); // Name field on the submit input.
    $form->send(); // EXECUTE!

}

Posted February 18, 2008

One Sexy Response to Tiny Form Class

jhj
had this to say...

hj

April 16, 2008 at 8:13 am

 

Feel free to put in your 2 cents. I need cash.

Code must be put in between <code> </code> tags or there will be no soup for you.

 

Recent lab work

  • Database CSV Class
  • imageTick for jQuery
  • wiggleSlide for jQuery
  • CSV 2 PHP 2 MySQL Insert
  • jTabber for jQuery
  • Ajax Star Rating
  • Tiny Form Class

Things I like

  • cakephp
    CakePHP Rapidly develop robust web applications
  • jquery
    jQuery Traversing the DOM just got a lot simpler
  • asparagus
    Asparagus Even more nutritious than programming
© boedesign.com 2008 - God bless Wordpress