nita Posted June 22, 2007 Share Posted June 22, 2007 Hi I have small recomendation form, which is expected to collect name, e-mail, message, than sent e-mail and also update mysql database. What is done ? - when fields are empty - ok - email validation - ok - captcha string validation - ok what i want to do is to make sure that no one can use my form to spam, and also i will not get spam too. also if filling up message if enter is pressed, will be displayed like in html <br> in both email and mysql database too. and last most important issue. My so called captcha, if im testing form and my form will be displayed again, captcha image is not changing, is not refreshing each time form is called. i need some advice on this topic ... please thanks a lot in advance my code so far .. $php_self = basename(htmlentities($_SERVER['PHP_SELF'])); //image captcha creator $im = ImageCreate(60, 20); //create image $white = ImageColorAllocate($im, 0,0, 0); $black = ImageColorAllocate($im, 120, 200, 68); $md5 = md5(microtime() * mktime()); $string = substr($md5,0,5); $verification = $string; $thevalue= $string; ImageFill($im, 0, 0, $black); ImageString($im, 4, 10, 3, $verification, $white); Imagejpeg($im, "inc/verify.jpeg"); ImageDestroy($im); //this is recommendation form $form .= " <table width='100%' border='0' cellspacing='0' cellpadding='10'> <tr> <td> <form action='".$php_self."' method='post'> <table width='444' align='left' class='info4'> <tr> <td valign='top' align='right'><b>Name:</b></td> <td valign='top'> <input name='name' size='30'> </td> </tr> <tr> <td valign='top' align='right'><b>E-mail:</b></td> <td valign='top'> <input name='email' size='30'> </td> </tr> <tr> <td valign='top' align='right'><b>Recomendation:</b></td> <td valign='top'> <textarea name='message' rows='10' cols='30'></textarea> </td> </tr> <tr> <td> <img src='inc/verify.jpeg' border='0'> <input type='hidden' value='".$thevalue."' name='thevalue1'> </td> <td> <input type='text' name='yourcode' size='5' maxlength='5'> </td> </tr> <td valign='top' align='right'></td> <td valign='top' align='left'> <input class='button1' type='submit' value='Send' name='submitreco'> <input class='button1' type='reset' value='Reset' name='reset'> </td> </tr> </table> </form> </td> </tr> </table><br>"; if (isset($_POST['submitreco'])) { $yourcode=$_POST['yourcode']; $thevalue1=$_POST['thevalue1']; $myemail = "[email protected]"; $name = $_POST['name']; $email = $_POST['email']; $message = $_POST['message']; // checking if empty .. if ($name=="" or $message=="" or $email=="") { echo "Please fill up all fields !"; echo($form); } else { $messagehtml = str_replace("\r", '', $message); $thanks = " <p align='left' class='info2'><span class='info2'> Thank you !. Your recomendation has sucessfuly been sent!<br> <br></span></p>"; $subject = "New Movie Recomendation from $name"; $headers = "From: [email protected]"; $messagetoemail = "Hi Kris. You recived a new movie recomendation. Name: $name E-mail: $email Recomendation: $messagehtml "; // e-mail validation if (($email)!="" and !preg_match("/([\w\.\-]+)(\@[\w\.\-]+)(\.[a-z]{2,4})+/i", $email)) { echo "Make sure that you fill in your e-mail corectly !"; echo($form); } else { if($yourcode == $thevalue1){ echo "$thanks"; mail($myemail, $subject, $messagetoemail, $headers); } else { echo "<span class='info2'> You verification code is not right. Please go back and try again. </span>"; echo($form); } } } } else { echo($form); } Link to comment https://forums.phpfreaks.com/topic/56731-form-with-captcha-validation-help-needed/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.