build-website-header
spacer-image
 

Contact Forms Part 2 - The Form

  

Here is an example form.

 

Website Feedback

Name:
Email address:
Comments:

 
 

There are two parts of this form I want to discuss. The first are the form fields that are used by either the JavaScript or PHP program (or both).

I've highlighted the email, name and comments fields in yellow. The name attribute is used as a variable in the script (PHP or Javascript).

The part of the form highlighted in blue is used for spam detection/prevention.

It is a way of trying to stop auto submit programs from filling out the form.

 <td width="370"><input type="text" name="name" size="25" /></td>
</tr>
<tr>
<td width="88"><b>Email address:</b></td>
<td width="370"><input type="text" name="email" size="25" /></td>
</tr>
<tr>
<td colspan="2" width="483"><b>Question:</b><br />
<textarea rows="15" cols="45" name="message">
</
textarea> </td>
</tr>
<tr>
<td align="center" colspan="2">
<p align="left">To Prevent Spam you are required to enter a validation<br />code to confirm that you are a real person and not a <br>
machine. The code is <b><font color="#000080">1234 <br>
</font></b>Just enter this code in the box below before you send</td>
<tr><td bgcolor="#FEFFE1"><b>Enter Code:</b></td><td><input type="text" name="valid" size="10" /></td></tr>
 


See website forms for more information about forms in general

The next part of the form I want to discuss is the part that does the form submission.

 This is at the very top of the form and begins with the form tag as shown here:

 <form onsubmit="return submitIt(this)" action="feedback.php" method="post"">
Note: This is optional if you don't use it then the code looks like this:

<form  action="feedback.php" method="post"">

The statement onsubmit="return submitIt(this)"  calls a Javascript funtion called submitit and passes the form itself as a variable.

This is done with special variable this.

The function is coded to analyse the form before it is submitted to the serve. The function will put an error alert if it finds a problem and the form will not be submitted to the server.

If the function completes it returns and then the action="feedback.php"  sends the form to the server to be processed by the php script called feedback.php.

So lets look at the feedback.php script in

 

Google
Web www.build-your-website.co.uk


 

spacer2-image