EZ Web Forms via E-Mail Print
Sunday, 30 April 2006

Listing the Questions

Next, you need to tell the form what questions it should be asking of the user. For example:

$questions  = array(

        array( 
"Text" 20 "Your First/Given Name"  ),
        array( 
"Text" 20 "Your Last/Family Name"  ),
        array( 
"Text" 32 "Your EMail Address"  ),
        array( 
"Text" 20 "Desired Appointment Date"  ),
        array( 
"Text" 10 "Desired Appointment Time"  ),

        );

Notice that the Questions variable contains an array of question arrays. Each question is an array containing three elements:

  • The type of data the user is being asked to provide. At the time of this writing, only one type of data is supported: text. Later, ezform may support additional types such as Yes/No, True/False, dates, times, text blocks, email address, etc.
  • The maximum number of characters anticipated in response to this question. At the time of this writing, this field length specification is not enforced, but it is used to estimate the required width of the text box that the user will be typing in.
  • The text of the question that the user will answer.

There is no limit on the number of questions you can have in the Questions array.

Preparation

ezform needs to prepare for the form handling operation. This is done when you pass the list of questions to the ezform object, like this:

$form -> prepare $questions  );

Normally, the $form->prepare($q) line does not emit any text into your web page. However, after a form has been processed and an email has been sent, this function will emit the Confirmation text.

Displaying the Form

Finally, you need to tell ezform where to display the list of form questions. There are two ways to do this:

  • Let ezform display the questions in a simple table format.
  • Create your own form layout and let ezform emit the necessary form-related HTML code only.

Simple Form Display

To let ezform display the questions automatically, just call the show() method of the form object, like this:

$form -> show ();

That's all you really need to do for a simple form. Ezform will emit a simple table with one line per form question. This table will be formatted in a very simple manner and is not necessarily going to win any prizes for appearance - but it will be easy to understand and use.

Advanced Form Display

If you want to make a bit more effort to make a pretty form, you can instruct ezform to provide all the necessary HTML form code like this:

echo  $form -> begin ();   // emit the <form> tag

echo  $form -> label ( 0 );  // emit the label text for the first question
echo  $form -> field ( 0 );  // emit the form code for the first question

echo  $form -> label ( 1 );  // ...second question...
echo  $form -> field ( 1 );  // ...second question...

echo  $form -> label ( 2 );  // ...etc...
echo  $form -> field ( 2 );  // ...etc...

echo  $form -> label ( 3 );  // ...etc...
echo  $form -> field ( 3 );  // ...etc...

echo  $form -> label ( 4 );  // ...etc...
echo  $form -> field ( 4 );  // ...etc...

echo  $form -> buttons ();  // emit the RESET and SUBMIT buttons
echo  $form -> end ();     // emit the </form> tag

Of course, this more advanced method requires that you surround the above PHP code with your own HTML web page formatting instructions in the expected manner:

<?= $form -> begin ();  ?>
<table border=0>
<tr>
   <td><?php = $form -> label ( 1 );  ?> </td>
   <td><?php = $form -> field ( 1 );  ?> </td>
</tr>
...
<tr><td colspan=2><?=$form -> buttons ();  ?> </td></tr>
</table>
<?=$form -> end ();  ?>

When the user views the resulting page, he will see the ezform. When he fills the form with data and submits the form, the form will perform a post operation back to the same web page. Ezform will collect the data and prepare an email which will be sent to the specified address. It will also emit the confirmation message to the web page so that the user will see that an email was sent.

For more information on how to use ezform, try the supplied test forms and play with them to see what happens when you make changes.



 
< Prev

Mailing List

To join our mailing list,
enter your email address
and press Subscribe:

AzerTech RSS


Copyright © 2010 by AzerTech.net, All rights reserved.
Powered By BNT Solutions, Inc.



Note: Site functionality is impaired when using IE6 or less.