This is my form code:
echo '
<div class="ctext" id="form">
<table><form method="post" action="prashanja.php">
<tr><td>Name:</td><td><input type="text" name="name"/></td></tr>
<tr><td>Question:</td><td><textarea cols="55" rows="4" name="prashanje"> </textarea></td></tr>
<tr><td></td><td >' . recaptcha_get_html($publickey) . '<button name="btn" value="submit">Enter</button></td></tr>
</form></table>
</div>';
And this is the validation code:
if (isset($_POST['btn'])) {
$name = mysql_real_escape_string(strip_tags($_POST['name']));
$prashanje = mysql_real_escape_string(strip_tags($_POST['prashanje']));
$date = time();
# the response from reCAPTCHA
$resp = null;
# the error code from reCAPTCHA, if any
$error = null;
# was there a reCAPTCHA response?
if ($_POST["recaptcha_response_field"]) {
$resp = recaptcha_check_answer($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]);
if ($resp->is_valid) {
$query = "INSERT INTO prashanja VALUES(NULL,'$name','$prashanje','','$date')";
if (!mysql_query($query))
echo 's... happens';
else
echo 'cool';
} else {
# set the error code so that we can display it
$error = $resp->error;
}
}
}
These segments are on the same page. The first segment generates the form and the second segment checks if the correct button is pressed, initializes the variables and than checks the recaptcha and does some operations. I get the error "Undefined index: recaptcha_response_field". I suspect that recaptcha won't work if the validation is done on the same page as the form that sent the variables. Are my suspicions correct and is it better if I move the validation code to another file?