Version 0.1
Tired of writing repetitive HTML for forms?
Create forms faster and maintain them easier with a form helper class.
Text Input
$object->input($label,$name,$value,$params);
Example: $form->input(‘First Name:’,'first_name’,'Joe’,array(‘size’=>’10′));
This will create the following:
<label for=”first_name”>First Name:</label> <input type=”text” name=”first_name” value=”Joe” size=”10″ />
The $params array can be any parameter you want it to be. You can put classes, styles, etc.
$value and $params are optional.
TextArea
$object->textarea($label,$name,$value,$params);
Example: $form->textarea(‘Comment:’,'comment’,'This is my comment.’,array(‘rows’=>’10′));
This will create the following:
<label for=”comment”>Comment:</label><textarea name=”comment” rows=”10″>This is my comment.</textarea>
The $params array can be any parameter you want it to be. You can put classes, styles, etc.
$value and $params are optional.
Select Dropdown
$object->select($label,$name,$value,$params);
Example: $form->select(‘How many kids do you have?’,'number_of_kids’,array(0,1,2,3,4));
This will create the following:
<label for=”number_of_kids”>How many kids do you have?</label><select name=”number_of_kids”>
<option value=”0″>0</option>
<option value=”1″>1</option>
<option value=”2″>2</option>
<option value=”3″>3</option>
<option value=”4″>4</option>
</select>
The $params array can be any parameter you want it to be. You can put classes, styles, etc.
$params are optional.
This class doesn’t have the option to create checkboxes or radio buttons, but that is definitely on the way in a future update. I hope this class helps you as much as it helps me out.
include "formHelper.php"; // Include the class file.
$form=new formBuilder(); // Initialize the helper.
echo $form->open('formProcessor.php','post'); // Open the form tag, list where it goes and how it is supposed to get there.
echo $form->input('First Name:','first_name'); // Create an text input field.
echo $form->select('How many kids do you have?','number_of_kids',array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15)); // Create a select dropdown.
echo $form->textarea('Comments','comments','',array('rows'=>'10')); // Create a textarea.
echo $form->submit('Submit It Now!'); //Create a submit button.
echo "</form>"; // Close the form tag.