Creating the mail template >> << Creating the HTML
Every field created in the form must be added to the script configuration.
The configuration file can be found in the script directory :
php/SimpleContactForm/SimpleContactForm.configuration.php
.
Field configuration settings are found in the fields
property.
It should look like this :
1 2 3 4 5 6 | $config [ 'fields' ] = array ( 'FIELD-NAME' => 'FIELD-OPTIONS' , OPTION2, OPTION3, ... ); |
FIELD-NAME
is the name that corresponds with the name used in the form HTML file.
FIELD-OPTIONS
can be left blank but all fields must have an entry in this array.
FIELD-OPTIONS
can contain multiple options separated spaces.
The most basic options used in the default form will be explained below; For a full description of all field options see the configuration reference page.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | $config [ 'fields' ] = array ( 'Name' => 'required maxLength=100' , 'Email' => 'required email maxLength=256' , 'Number' => 'required maxLength=100' , 'Message' => 'required maxLength=800' , // Use some logic to provide the appropriate validation depending // on the verification type (text based or image) 'Verification' => 'required verification ' . ( $config [ 'useTextCaptcha' ] || !self:: $supportsGD ? 'integer maxLength=2' : 'alphanum maxLength=7' ) ); |
The Name
field contains two options : required
and maxLength
.
Any field with the required
option set cannot be left empty.
maxLength
indicates a maximum allowed
length for a fields value, any value longer than that is considered invalid.
Certain options, such as maxLength
, require a parameter; all such option will have the following format :
OPTION-NAME=VALUE
.
The Email
field contains the email
option. This tells the script to expect an email.
The validator only performs a basic check to determine that the fields value is formatted like an email and does
not check whether the email actually exists or not.
The Verification
fields contains 3 other options.
The first is verification
. This is required for the verification field and checks the fields value against the
verification value. If they do not match exactly the field is considered invalid.
The integer
option indicates that a field may only contain digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) and no other
characters.
alphanum
is short for alpha numeric and means that the field may only contain uppercase letters (A-Z), lowercase
letters (a-z) and numbers (0-9).
The Verification
field also contains some logic to choose its options. The line :
1 | $config [ 'useTextCaptcha' ] || !self:: $supportsGD |
first checks the useTextCaptcha
setting to determine what kind of captcha to use (text or image).
Then, if the image based captch has been used, the supportsGD
property is checked to ensure that GD library
which is required to render the captcha image is supported by the server running the script.
The text based captcha expects a single number so the first line (integer maxLength=2
) limits the field to integer
values with at most two digits.
The captcha image (alphanum maxLength=7
) requires a verification code that may contain letters or number
with at most 7 characters.
The value of the maxLength
option should match the value specified in the captcha image configuration.
For more information on the captcha image see :
SecurityImage.configuration.php