/ Published in: PHP

URL: http://www.thatgrafix.com
A simple to use framework for a contact form. This is missing some serious validation and such but is a good startin' point for any simple contact form.
The input field named 'botty' is an input field we hide with css.. if data is sent to the handling file from that field then we know a non-human filled this form out.. and it kills the script.
** just added some simple jscript to handle some mild validation.
Expand |
Embed | Plain Text
CSS <style type="text/css"> #botty {display:none;} <style> Javascript <script type="text/javascript"> function checkform(form){ // check first name if (form.FirstName.value == "") { alert( "Please enter your First Name." ); form.FirstName.focus(); return false ; } // check last name if (form.LastName.value == "") { alert( "Please enter your Last Name." ); form.LastName.focus(); return false ; } // check email field if (form.email.value == "") { alert( "Please enter your Email Address." ); form.email.focus(); return false ; } // check for valid email addy var apos=form.email.value.indexOf("@"); var dotpos=form.email.value.lastIndexOf("."); if (apos<1||dotpos-apos<2){ alert("Not A Valid Email Address!"); return false; } // ** END ** return true ; } </script> HTML <form action="contact_handle.php" method="post" name="formy" id="formy"> <p>* Required</p> <table cellspacing="0" cellpadding="2" border="0" class="webform"> <tbody> <tr> <td><label for="Title">Title</label> <br /> <select name="Title" id="Title" class="cat_dropdown_smaller"> <option value="126631">DR</option> <option value="126629">MISS</option> <option value="126627" selected="selected">MR</option> <option value="126628">MRS</option> <option value="126630">MS</option> </select></td> </tr> <tr> <td><label for="FirstName">First Name</label> <br /> <input name="FirstName" type="text" class="cat_textbox" id="FirstName" size="35" maxlength="255" /> *</td> </tr> <tr> <td><label for="LastName">Last Name</label> <br /> <input name="LastName" type="text" class="cat_textbox" id="LastName" size="35" maxlength="255" /> *</td> </tr> <tr> <td><label for="email">Email Address</label> <br /> <input name="email" type="text" class="cat_textbox" id="email" size="35" maxlength="255" /> *</td> </tr> <tr> <td><label for="comments">Comments/Enquiries</label> <br /> <textarea name="comments" cols="45" rows="8" class="cat_listbox" id="comments" onkeydown="if(this.value.length>=1024)this.value=this.value.substring(0,1023);"></textarea></td> </tr> <tr> <td><input name="subscribe" type="checkbox" id="subscribe" value="yes" /> Subscribe to: Email List Signup</td> </tr> <tr> <td><input type="submit" class="cat_button" value="Submit" id="catwebformbutton" /> <span id="formHide"><input type="text" id="botty" name="botty" /></span> </td> </tr> </tbody> </table> </form> PHP <?php //form data // prove if a bot has entered data if($botty != NULL){ echo "barghh! darn bot!"; die; } // the email address where the script will email the form results to // where the email will look like it is sent from $subject = "Email from your website"; $body = "Email from your website" . " "; $body .= "Name: " . $FirstName . $LastName . " "; $body .= "Email: " . $email . " "; $body .= "Newsletter: " . $subscribe . " "; $body .= "Comments: " . $comments . " "; $headers = "From: $from" . " "; $headers .= "Reply-To: $from" . " "; $headers .= "Return-Path: $from" . " "; // mail(to,subject,body,headers); if($isMailed){ echo "Thank you for your inquery, " . $FirstName . " " . $LastName . " We will get back to you shortly."; }else{ echo "There seemed to be a problem"; } ?>
Comments

You need to login to post a comment.
Hi This is my first go at setting up a contact form, I have used the above but can't seem to get it working.
I suspect it is the link between the form and the php, when I try to test the form my browser is asking me if I wish to open the .php file!?!
I suspect it is within the form actions"" parameter but have tried a few things. Can someone talk me through set-up in basic terms,thanks Mark
Hi This is my first go at setting up a contact form, I have used the above but can't seem to get it working.
I suspect it is the link between the form and the php, when I try to test the form my browser is asking me if I wish to open the .php file!?!
I suspect it is within the form actions"" parameter but have tried a few things. Can someone talk me through set-up in basic terms,thanks Mark
Hi This is my first go at setting up a contact form, I have used the above but can't seem to get it working.
I suspect it is the link between the form and the php, when I try to test the form my browser is asking me if I wish to open the .php file!?!
I suspect it is within the form actions"" parameter but have tried a few things. Can someone talk me through set-up in basic terms,thanks Mark
Mark, I see it was some time ago that you posted your question, and you presumably have found the answer by now. But I thought I would answer it anyway, since I created an account specifically to answer it, before I noticed the date, and it may help someone else!
My guess is that you are testing the script by attempting to open it in a web browser on your own computer. PHP doesn't work like that, it needs to be on a server, generally the browser can't understand php. When the script is run it creates an HTML web-page which is sent to your web-browser which it can display. You can't leave out the server because then the web-page is never generated.
In order to delete bing search history you may make use of this portal remove bing search history which includes all advantageous information by which your work will be all easier. Have a visit for once surely you will having all beneficial information.