greenway Posted August 16, 2007 Share Posted August 16, 2007 I have a captcha script up and working and want to add it to a comment script I run. Does anyone know how to add it to the comment form please ? Quote Link to comment https://forums.phpfreaks.com/topic/65247-how-do-i-add-my-captcha-script-to-a-form/ Share on other sites More sharing options...
lightningstrike Posted August 16, 2007 Share Posted August 16, 2007 You open the code for the comment form and add it. If it has documentation then read that and act. If you made it yourself you can probably figure it out on your own. Quote Link to comment https://forums.phpfreaks.com/topic/65247-how-do-i-add-my-captcha-script-to-a-form/#findComment-325807 Share on other sites More sharing options...
greenway Posted August 16, 2007 Author Share Posted August 16, 2007 I am in no way up to making the form myself,it was a script I got off the internet 12 months ago that I have been running but is now hit with spam. My comment script: // connect to database $dbh = mysql_connect ($db_hostname, $db_username, $db_pass) or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ($db_name); $tuturl = $_POST["tuturl"]; $tutid2 = $_POST["tutid2"]; $name = $_POST["name"]; $url = $_POST["url"]; $email = $_POST["email"]; $message = $_POST["message"]; $sendcomment = mysql_query("INSERT INTO comments SET tutorialid='$tutid2', name='$name', url='$url', email='$email', comment='$message', date=now()"); if($sendcomment){ //header("Location: $tuturl"); echo "<h1>Submission Successful</h1>"; echo "Your comment has been submitted to admin for consideration. You will now be redirected back to the last page you visited. Thanks!"; echo "<meta http-equiv='refresh' content='2;URL=$tuturl'>"; } else { echo "There was an error with the submission. "; } ?> And this is the captcha script: <html> <div align="center"></div> <? $imgcode = ""; include "src/config.php"; for ($i=0; $i<$symbols; $i++){ $imgcode .= code(mt_rand(0,24))."|"; } if($code && !$imagetext){ $error = 1; $errstr = "Please Enter the image code"; }elseif($code && $imagetext){ $chart = explode('|', $code); for ($i=0; $i<5; $i++){ $chart[$i] = decode($chart[$i]); $chek .= $letter[$chart[$i]]; } if($chek != strtoupper($_POST['imagetext'])){ $error = 1; $errstr = "You entered incorrect image code"; }elseif($chek == strtoupper($_POST['imagetext'])){ $error = 1; $errstr = "You entered Correct image code. Thank you!"; } } if($error) print "<FONT SIZE=4 COLOR=BB0000>$errstr</FONT>"; print <<<FO <form method="POST"> <table cellpadding="5" cellspacing="1" width="100%"> <tr> <td align="center">Validation</td><input type="hidden" name="code" value="$imgcode"> <td align="center"><img src="button.php?c=$imgcode" border=0> <input size=10 type="text" name="imagetext"></td> </tr> <tr> <td align="center" colspan="2">Enter the text above to validate your submission.<BR> <FONT SIZE=3>'Reload this page if you cant read the above image'</FONT> </td> </tr> <tr> <td align="center" colspan="2"><input type="submit" name="submit" value="Test Form"></td> </tr> </table> </form> FO; ?> </center> </body> </html> I have both scripts working but have no idea how to add the captcha script to the comment script. Quote Link to comment https://forums.phpfreaks.com/topic/65247-how-do-i-add-my-captcha-script-to-a-form/#findComment-325852 Share on other sites More sharing options...
Reeka Jean Posted August 16, 2007 Share Posted August 16, 2007 Since you don't have the html bit of your comment form posted, I don't think anyone is going to be able to show you specifically where to put each part. Basically, you'll add the php code to your php code and the html code to your html code. Quote Link to comment https://forums.phpfreaks.com/topic/65247-how-do-i-add-my-captcha-script-to-a-form/#findComment-325998 Share on other sites More sharing options...
greenway Posted August 16, 2007 Author Share Posted August 16, 2007 Sorry is it this bit ? <?php //create the form to submit comments //you can add more fields, but make sure you add them to the db table and the page, submitcomment.php echo " <a name=\"post\"> <div id=\"submitcomment\" class=\"submitcomment\"> <form name=\"submitcomment\" method=\"post\" action=\"submitcomment.php\" onSubmit=\" return form_Validator(this)\"> <table width=\"100%\"> <tr> <th colspan=\"2\"><h3 class=\"formtitle\">Leave your comment:</h3></th> </tr> <tr> <th scope=\"row\"><p class=\"req\">Name:</p></th> <td><input class=\"form\" tabindex=\"1\" id=\"name\" name=\"name\" /></td> </tr> <tr> <th scope=\"row\"><p class=\"opt\">Email:</p></th> <td><input class=\"form\" tabindex=\"2\" id=\"email\" name=\"email\" /></td> </tr> <tr> </tr> <tr valign=\"top\"> <th scope=\"row\"><p class=\"req\">Comments:</p><br /></th> <td><textarea class=\"formtext\" tabindex=\"4\" id=\"message\" name=\"message\" rows=\"10\" cols=\"40\"></textarea></td> </tr> <tr> <td> </td> <td><input type=\"submit\" name=\"post\" class=\"submit\" value=\"Submit Comment\" /><br /> <p>Note:<br>All comments are moderated before going live due to spam abuse. </td> </tr> </table> <input type=\"hidden\" name=\"tuturl\" value=\"$tuturl\" /> <input type=\"hidden\" name=\"tutid2\" value=\"$tutid2\" /> </form> Quote Link to comment https://forums.phpfreaks.com/topic/65247-how-do-i-add-my-captcha-script-to-a-form/#findComment-326009 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.