i made a contact form with CAPTCHA technology.i need help writing the form submission file i.e send.php and the AJAX code using prototype or mootools libraries.i want the code in such a way tht the seucrity code is checked for accuracy as soon as it typed in and only when it is correct then only can the user submit the form.the codes i've written so far for the different sections are below.there seems to be an error in the send.php file.
Code for header section of the contact us page
Code for the actual form
send.php
Code for header section of the contact us page
| Code: |
|
<script type="text/javascript" src="scripts/mootools.js"></script> <script type="text/javascript"> window.addEvent('domready', function(){ $('contact').addEvent('submit', function(e) { new Event(e).stop(); var log = $('log_res').empty().addClass('ajax-loading'); this.send({ update: log, onComplete: function() { log.removeClass('ajax-loading'); } }); }); }); </script> |
Code for the actual form
| Code: |
|
<?php // check for posted form if (isset($_POST['submit'])) { // see if the code the user typed matched the generated code if (!empty($_SESSION['code']) && strtoupper($_POST['code']) == $_SESSION['code']) { unset($_SESSION['code']); echo '<font class="required">Congratulations, you entered the correct code. Your form has been successfully submitted. Please wait upto 48 hours for a reply. Thank you.</font>'; } else { echo '<font class="required">You have entered the wrong code. Please try again.</font>'; } } else { ?> <form action="send.php" method="POST" name="contact" id="contact"><table align=left cellpadding=0 cellspacing=2 style="padding-top: 10px;padding-left: 10px;"> <tr><td><label>Name<font class="required">*</font>:</label></td><td><input type=text class="input" name="name" size=50 style="background:url(images/user.png) no-repeat;padding-left:18px;"></td></tr> <tr>td> </td></tr> <tr><td><label>Email<font class="required">*</font>:</label></td><td><input type=text class="input" name="email" size=50 style="background:url(images/email.png) no-repeat;padding-left:18px;"></td></tr> <tr>td> </td></tr> <tr><td><label>Message<font class="required">*</font>:</label></td><td><textarea type=text class="input" name="msg" rows=200 cols=55 style="height:200px;"></textarea></td></tr> <tr>td> </td></tr> <tr><td> </td><td><img src="security-image.php?width=144" width="144" height="30" alt="Security Image" style="border: 1px solid #878A8C" /></td></tr> <tr>td> </td></tr> <tr><td><label>Security Code<font class="required">*</font>:</label></td><td><input type="text" class="input" size="50" name="code" id="code" value="" /></td></tr> <tr>td> </td></tr> <tr><td> </td><td><input type=submit class="button" name="submit" value="Submit" id="submit"> <input type="reset" class="button" name="reset" value="Clear"></td></tr> <tr><td> </td><td><font class="required">* marks a required field</font></td></tr> </table></form> <?php } ?> |
send.php
| Code: |
|
<?php error_reporting(E_NOTICE); function valid_email($str) { return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE; } if($_POST['name']!='' && $_POST['email']!='' && $_POST['msg']!='' && valid_email($_POST['email'])==TRUE && strlen($_POST['msg'])>30) { $to = 'admin@verticalaxis.frih.net'; $headers = 'From: '.$_POST['e_mail'].''. "\r\n" . 'Reply-To: '.$_POST['e_mail'].'' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); $subject = "Contact Us"; $message = htmlspecialchars($_POST['msg']); mail($to, $subject, $message, $headers) } ?> |
