Hi everyone. I'm still pretty new to PHP so am struggling to implement things at the moment.
At the moment I have a feedback form on a website which works really well. But due to a recent spate of "spam" via the form, I would like to implement a "captcha" script to force users to enter a confirmation code before allowing the form to be processed and emailed.
I have found a script at http://www.white-hat-web-design.co.uk/articles/php-captcha.php but am struggling to get it to work with my current form handling script. I'm not sure which bits go where basically.
Here is the code the website asks you to include on your form page.
I've done this ok just by adding it within the form code on the website.
You're then asked to include the below in your form handling script.
Here is my current form handling script. Can anybody help me in re-arranging it to work with the above?
My problem is the empty check part adds extra ifs to the equation and I'm worried that it'll all go wrong. The form processing bit is in sections in my code
- the variable setting
- the empty check
- the mail bit.
The error bit is the html after the empty check.
If anyone can get this working for me I'd greatly appreciate it, and will make a note of it all for future reference so I know how.
At the moment I have a feedback form on a website which works really well. But due to a recent spate of "spam" via the form, I would like to implement a "captcha" script to force users to enter a confirmation code before allowing the form to be processed and emailed.
I have found a script at http://www.white-hat-web-design.co.uk/articles/php-captcha.php but am struggling to get it to work with my current form handling script. I'm not sure which bits go where basically.
Here is the code the website asks you to include on your form page.
| Code: |
|
<img src="CaptchaSecurityImages.php" /> Security Code: <input id="security_code" name="security_code" type="text" /> |
I've done this ok just by adding it within the form code on the website.
You're then asked to include the below in your form handling script.
| Code: |
|
<?php session_start(); if(($_SESSION['security_code'] == $_POST['security_code']) && (!empty($_SESSION['security_code'])) ) { // Insert you code for processing the form here, e.g emailing the submission, entering it into a database. unset($_SESSION['security_code']); } else { // Insert your code for showing an error message here } ?> |
Here is my current form handling script. Can anybody help me in re-arranging it to work with the above?
| Code: |
|
<?php $contactname = $_REQUEST['contactname'] ; $email = $_REQUEST['email'] ; $email2 = 'me@mydomain.com' ; $club = $_REQUEST['club'] ; $query = $_REQUEST['query'] ; $comments = $_REQUEST['comments'] ; if (!isset($_REQUEST['email'])) { header( "Location: http://www.ldbsa.co.uk/feedback.php" ); } elseif (empty($email) || empty($club) || empty($query) || empty($comments) || empty($contactname)) { echo '<h1>ERROR</h1><p>Not all fields have been filled in. Please try again.</p><p><a href="feedback.php"><< Back to form</a></p>'; } else { mail( "$email, $email2", "Thank you for your feedback/questions", "<p>Name: $contactname</p> <p>E-Mail Address: $email</p> <p>Your club: $club</p> <p>Your query was regarding: $query</p> <p>Comments/Questions: $comments</p>", "To: $contactname <$email>\n" . "From: LDBSA <$email2>\n" . "MIME-Version: 1.0\n" . "Content-type: text/html; charset=so-8859-1"); header( "Location: http://www.ldbsa.co.uk/thanks.php" ); } ?> |
My problem is the empty check part adds extra ifs to the equation and I'm worried that it'll all go wrong. The form processing bit is in sections in my code
- the variable setting
- the empty check
- the mail bit.
The error bit is the html after the empty check.
If anyone can get this working for me I'd greatly appreciate it, and will make a note of it all for future reference so I know how.
