简单的PHP联系人表单+jscript验证+anti-bot
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了简单的PHP联系人表单+jscript验证+anti-bot相关的知识,希望对你有一定的参考价值。
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.
CSS <style type="text/css"> #botty {display:none;} <style> <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> <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"; } ?>
以上是关于简单的PHP联系人表单+jscript验证+anti-bot的主要内容,如果未能解决你的问题,请参考以下文章
是否有一个简单的解决方案可以将 PHP 联系表单重定向回我的网站? [复制]
如何知道 Ant-Design 表单中的所有字段何时被验证(添加值)?