Here is something you can do with PHP. In my mind, it would be the
easiest and most every hosting company comes with PHP installed.
First, how to set up a form...
Text Fields:
<input type="text" name="FirstName">
<input type="text" name="LastName">
These can be named at your pleasure. Whatever is in the 'name'
element in the input will result in your email reading 'name=value'.
For instance, in the
case above, if a user enters 'Bob Hart' in the box, when submitted the
email will read "FirstName = Bob Hart".
Text Areas:
<textarea name="Comments" rows="5" cols="25"></textarea>
<textarea name="Interests" rows="3" cols="15"></textarea>
These can also be named at your pleasure. Same as text field, the
'name' element is what the email will display along with whatever is
inputed. The
'rows' defines the size of the box in 'rows' or horizontal and 'cols'
or (vertical)
Radio Buttons:
<input type="radio" name="Age" value="18-25">
<input type="radio" name="Age" value="26-35">
<input type="radio" name="Age" value="35+">
Now this is where it gets tricky. Radio buttons are usually within a
group of buttons. Ie, to select the age of a person. The whole group
MUST have the
same 'name' element. In the one above, the group's name is 'Age' and
note the different values. So, say if the user selects the '18-25'
radio button, the
email would read "Age = 18-25". Note: you can place as many groups of
radio buttons you want on a single form.
Checkbox Variation 1
<input type="checkbox" name="Accepted">
This is the simpler of the two variations of form handling of
checkboxes. This simply will display in your email a 'on' or 'off'.
'On' being yes, and 'off'
being no. So in this case if the user selects this checkbox, the email
would read "Accepted: on"
Checkbox Variation 2
<input type="checkbox" name="Sports[]" value="Badmitten">
<input type="checkbox" name="Sports[]" value="Soccer">
<input type="checkbox" name="Sports[]" value="Golf">
This works much like the radio buttons, whereas you can group sets of
checkboxes together. Trickier than before is the '[]' at the end of
the 'name'
element. This tells the parser that 'Sports' will contain more than
one value. Say if your question is "What sports do you like?" and you
list a group of
textboxes (Badmitten, Soccer, Golf etc), if the user checks say golf
and soccer, the email will say "Sports: Golf, Baseball". To add more
items in the
group, simply ad a new input type and change the 'value' element to
your desired value NOT the 'name'.
Selects (or pulldown menus) -
<select name="FavoriteMonth">
<option value="January">January</option>
<option value="February">February/option>
<option value="March">March</option>
...
</select>
Much like checkbox variation 2, but easier, you are allowing the user
to select from a myriad of 'options'. In thie case their favorite
month. As you can
see, the 'value' or the option will result in what that will read in
the email if selected. So, if the user pulls down the menu and
selects 'February' the email
would read "FavoriteMonth = February".
Now, that all said and done, here is the code for the parse. You
should place this on your server in the same directory where the
form's page is. You
MUST change the '$email_to' variable so it will send it to your
desired email address. Also listed below is an example form.
-----------------
Form Example
-----------------
<form method="POST" action="formmail.php">
<table border=0 cellpadding=0 cellspacing=0>
<tr>
<td colspan=2><B>Your Information?</B></td>
</tr>
<tr>
<td>Name: </td><td><input type="text" name="Name"></td>
</tr>
<tr>
<td>Email: </td><td><input type="text" name="Email"></td>
</tr>
<tr>
<td colspan=2><BR><B>What Sports Do You Like?</B></td>
</tr>
<tr>
<td>Basketball: </td><td><input type="checkbox" name="Sports[]"
value="Basketball"></td>
</tr>
<tr>
<td>Volleyball: </td><td><input type="checkbox" name="Sports[]"
value="Volleyball"></td>
</tr>
<tr>
<td>Soccer: </td><td><input type="checkbox" name="Sports[]"
value="Soccer"></td>
</tr>
<tr>
<td>Badmitten: </td><td><input type="checkbox" name="Sports[]"
value="Badmitten"></td>
</tr>
<tr>
<td colspan=2><BR><B>How Old Are You?</B></td>
</tr>
<tr>
<td>18-24: </td><td><input type="radio" name="Age"
value="18-24"></td>
</tr>
<tr>
<td>25-35: </td><td><input type="radio" name="Age"
value="25-35"></td>
</tr>
<tr>
<td>35+: </td><td><input type="radio" name="Age" value="35+"></td>
</tr>
<tr>
<td>35+: </td><td><input type="radio" name="Age" value="35+"></td>
</tr>
<tr>
<td><B>Favorite Month:</td><td>
<select name="FavoriteMonth">
<option value="January">January</option>
<option value="February">February</option>
<option value="April">April</option>
<option value="May">May</option>
</select>
</td>
</tr>
<tr>
<td colspan=2><BR><B>Comments?</B></td>
</tr>
<tr>
<td colspan=2><textarea name="Comments" rows="5"
cols="25"></textarea></td>
</tr>
<tr>
<td colspan=2><BR><B>Do you like this (Check if yes)?</B></td>
</tr>
<tr>
<td> </td><td><input type="checkbox" name="LikeThis"></td>
</tr>
<tr>
<td> </td><td><input type="submit" value="Submit"></td>
</tr>
</table>
</form>
------------------------
PHP Parse File (Change The two variables at the top and save as
'formmail.php')
------------------------
<?php
// variables
$mail_to = "youremail@yourdomain.com";
$redirect_to = "redirectthanks.html";
// if posted data
if ($_POST)
{
$body = "";
// go through all form elements
foreach ( $_POST as $key => $value )
{
// if element is array (checkboxes)
if ( is_array ($value))
{
$body .= $key . " = ";
foreach ($value as $hey)
$body .= $hey . ", ";
$body .= "\r\n";
// else if regular elements
} else {
// display form field = form value
$body .= $key . " = " . "$value\r\n";
}
}
// send the mail
mail( $mail_to , "Form Submission" , $body);
// redirect
header("Location: $redirect_to");
exit();
}
?>
I hope that works!! |