Hey all, I'm having a bit of a problem with a custom commenting system for my website. See, when you submit a comment, you have to fill in a reCaptcha to verify that you're not a spambot. If it returns false, you see an error: however, I want to keep the comment box filled out with whatever comment the person tried to submit. For example, if somebody writes a comment, fills out the CAPTCHA wrong, hits submit, it returns a CAPTCHA error but the comment box is now empty. I want to keep the comment box intact. The main issue here is that my code works like this: $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); if (!$resp->is_valid) { header("location: http://zconnect.org.uk/article/".$action."&error=1#comment"); // If it's wrong, redirect to the post comment section of the article but display an error } else { // Insert the comment } Code (markup): Because I'm using header(), the POST data is not kept intact. What can I do to fix this?
post the data or use get to store ur data..and then recall it inside ur text box/area like: <textarea name=mycomment><?php echo $_POST['mydata']; ?></textarea> so after you post the comment if it was wrong it should pass $_POST['mydata'] value inside the textarea again..
Two options: A) don't do the redirect and simply show the form again on the same page, then use the $_POST variables as in the post above. (With 1 distinction, be sure to htmlspecialchar() the $_POST fields). B) Put your $_POST data in a session, then use those values on the redirected page and be sure to unset the session data again. If I were to choose, it would be option A.
<input name="comment" type="text" value="<?php echo (isset($_POST['comment'])) ? $_POST['comment'] : ''; ?>" /> Code (markup):