|Custom warnings||If you need to move warnings somewhere else, you can set the form plug-in to queue warnings until you tell it to display them.|
|Easy SQL in PHP||This PHP plug-in makes it a lot easier to work with SQL databases on your PHP pages.|
|Email Form||Have your form data sent automatically to your e-mail address from any form on a PHP web page.|
include_once("/web/includes/forms.phpi"); $contactForm = new Form();You should put this at the very top of your PHP web page. Otherwise, some functions will fail.
Get dataIf you want a simple list of all of the data from your form, you can use $contactForm->displayFields(). If you want them joined with something special, such as a break, pass that as an argument. For example:
$contactForm->displayFields();By default, the data is displayed as a table. You can also use $contactForm->allFields() to get the list back broken up by carriage returns. You might use this to pass the list to another function, such as to the Mail Queue plug-in.
Valid dataBy default, the form will accept data from both POST and GET methods, and from cookies. You can specify that the plug-in only pays attention to a subset of those types (as well as FILE), by adding that as a parameter when you make the new form:
//only accept GET data $contactForm = new Form("get") //accept both GET and COOKIE data $validSources = array("get", "cookies"); $contactForm = new Form($validSources);The valid types are get, post, cookies, and files. If you need to add more methods later in your script, you can use $contactForm->addMethods() to add them. You can (and should) also specify what fields constitute a valid submission. If you don’t specify a list of valid fields, then the plug-in will assume that any data sent to it is worth looking at.
$validFields = array("name", "address", "age"); $contactForm = new Form("get", $validFields);
RequirementsThe most basic requirement is that some fields cannot be empty. Use the required() method to specify these. You can also use the numeric() method to specify that a field or fields must only contain numbers.
$requiredFields=array('name', 'address'); $contactForm->required($requiredFields); $contactForm->numeric('age');
Start and end the form
<?$contactForm->start();?> <p>Name: <?$contactForm->text("name");?></p> <p>Address: <?$contactForm->text("address");?></p> <p>Age: <?$contactForm->text("age");?></p> <p><?$contactForm->submitbutton();?></p> <?$contactForm->end();?>If you want the form to have a special style, you’ll need to tell the plug-in this before you start the form.
$contactForm = style("contacts");
<?IF ($contactForm->verify()):?> <p>Thank you for submitting this form!</p> <?ELSE:?> <?$contactForm->start();?> <p>Name: <?$contactForm->text("name");?></p> <p>Address: <?$contactForm->text("address");?></p> <p>Age: <?$contactForm->text("age");?></p> <p><?$contactForm->submitbutton();?></p> <?$contactForm->end();?> <?ENDIF;?>The verify() method will check that all required fields were submitted and that numeric fields are numeric; if anything is wrong, it will display a list of the incorrect submissions.
ChoicesSome fields are a list of choices. Only those choices are valid. Rather than having the person type them in, we can make it be a multiple choice field. First, you need to give the plug-in an array of choices.
<? $contactForm->choices('cakes', $validcakes); ?>Now, when you put this field on your form, you can use multiplechoice() to place it as a series of checkboxes.
<p>Cake: <? $contactForm->multiplechoice('cakes'); ?></p>When you specify that a field is a list of choices, verification will also ensure (on the server) that the field does contain one of those choices if the field has been entered. By default, the form will automatically pre-select choices after the form has been submitted if you redisplay the form. If you want some choices to be pre-selected even before the form has been submitted, pass those as an array:
<p>Cake: <? $contactForm->multiplechoice('cakes', array('angel', 'devil', 'is a lie')); ?></p>Option choices submitted via the form will take precedence over the provided defaults.
Advanced information for your scriptAll that the above does is to verify form submission. It doesn’t do anything with the form data. What you do with the form data is up to you. This plug-in is designed for custom forms. But it does have some features that you can use to make handling your form data easier. You can get the value of any submitted field using the fieldValue() method.
$name = $contactForm->fieldValue('name');This returns the first valid POST, GET, or COOKIE value that it finds.