Need php for adding Recaptcha to Form Answer may be simple!
Posted: Sun Jan 22, 2012 6:17 pm
Hi, This is solh:
I am not that experienced at html and php but I managed to create a contact form and php script for sending emails to my hotmail account and it has been working fine.
Now i wanted to add Recaptcha to that form and I did it successfully. But now I would like some help on the next topics:
I want to make recpatcha work with my form
when recaptcha is Incorrect I want to keep the information fields and Not send the email also Not show the "thank you your message has been sent".
only when recaptcha is Correct: send the email, clear the information fields, show "thank you message has been sent"
SORRY i FORGOT TO MENTION THIS SCRIPT IS ALL IN ONE PAGE CALLED "CONTACTFORM.PHP"
Thank you very much for your answers! If you can provide some details for the answer would be great!!!
Any help will be very appreciate!
This is my php and html scrpit for my contact form including recaptcha.
I am not that experienced at html and php but I managed to create a contact form and php script for sending emails to my hotmail account and it has been working fine.
Now i wanted to add Recaptcha to that form and I did it successfully. But now I would like some help on the next topics:
I want to make recpatcha work with my form
when recaptcha is Incorrect I want to keep the information fields and Not send the email also Not show the "thank you your message has been sent".
only when recaptcha is Correct: send the email, clear the information fields, show "thank you message has been sent"
SORRY i FORGOT TO MENTION THIS SCRIPT IS ALL IN ONE PAGE CALLED "CONTACTFORM.PHP"
Thank you very much for your answers! If you can provide some details for the answer would be great!!!
Any help will be very appreciate!
This is my php and html scrpit for my contact form including recaptcha.
Code: Select all
<?php
if ($_POST['parse_var'] == "form1"){
$emailTitle = 'Email from my website!';
$emailAddress = 'myemail@hotmail.com';
/* Gathering Data Variables */
$emailField = $_POST['email'];
$phoneField = $_POST['phone'];
$nameField = $_POST['name'];
$subjectField = $_POST['subject'];
$messageField = $_POST['message'];
$body = <<<EOD
<br><hr><br>
Email: $emailField <br />
Phone: $phoneField <br />
Name: $nameField <br />
Subject: $subjectField <br />
Message: $messageField <br />
EOD;
$headers = "From: $emailField\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail("$emailAddress", "$emailTitle", "$body", "$headers");
$sent = "Thank you! Your message has been sent.";
}
?>
<form id="form1" name="form1" method="post" action="contactform.php">
<table width="100%" border="0" cellspacing="6" cellpadding="0">
<tr>
<td align="right"><label for="email" class="titulos">Email: </label></td>
<td align="left"><input name="email" type="text" id="email" size="35" maxlength="50" />
*</td>
</tr>
<tr>
<td align="right"><label for="phone" class="titulos">Phone: </label></td>
<td align="left"><input name="phone" type="text" id="phone" size="35" maxlength="50" /></td>
</tr>
<tr>
<td align="right"><label for="name" class="titulos">Name:</label></td>
<td align="left"><input name="name" type="text" id="name" size="35" maxlength="30" />
*</td>
</tr>
<tr>
<td align="right"><label for="subject" class="titulos">Subject:</label></td>
<td align="left"><input name="subject" type="text" id="subject" size="35" maxlength="60" /></td>
</tr>
<tr>
<td align="right" valign="top"><label for="message" class="titulos">Message:</label></td>
<td align="left"><p>
<textarea name="message" cols="27" rows="5" id="message"></textarea>
*</p></td>
</tr>
<tr>
<td align="right"> </td>
<td align="left">
<?php
if (isset($_POST['send'])) {
require_once('recaptchalib.php');
$privatekey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
echo "Please try again";
} else {
echo "Correct";
}
}
?>
<?php
require_once('recaptchalib.php');
$publickey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; // you got this from the signup page
echo recaptcha_get_html($publickey);
?>
</td>
</tr>
<tr>
<td align="right"><label for="reset"></label></td>
<td align="left"><label for="send"></label>
<input type="hidden" name="parse_var" id="parse_var" value="form1" />
<input name="send" type="submit" id="send" onclick="MM_validateForm('email','','RisEmail','name','','R','message','','R');return document.MM_returnValue" value="Send Email" /> <label for="reset"></label>
<input type="reset" name="reset" id="reset" value="Reset form" /></td>
</tr>
<tr>
<td align="right"> </td>
<td align="left" class="content">(*) Are Required fields</td>
</tr>
<tr>
<td colspan="2" align="center"><?php print "$sent"; ?>
</td>
</tr>
</table>
</form>