Validate The Form Using Recaptcha, On Success Post Data To New Form
#1
Posted 30 November 2012 - 06:31 AM
I'm new to php, i've been struggling for 2 days to write a simple code with recaptcha. My requirements is
i have a registration form (reg.php) with 20 fields on it after all the required information is filled in the form data is submitted to Create Account page (CreateAccount.php).
I placed a recaptcha control on the first page (reg.php) to secure the form from bots. I'm doing some javascript validation on the client side for required fields, and finally validating if correct recaptcha code is entered on the server side. That means the form is submitted to itself first for recaptcha validation, after the code is valid i want to resubmit the data to Account Creation page. i don't know how to do this. the CreateAccount.php has got a complex logic so i can not move it to the same reg.php page.
i tried the following but with no luck...
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) {
//redirect to AccountCreation.php
header("Location: AccountCreation.php");
} else {
$error = $resp->error;
}
}
please help me how this is done is php. Is there any other way of doing it simply...
#2
Posted 30 November 2012 - 08:20 AM
Header("Location: http://mydomain.com/AccountCreation.php?user=blah&name=blahblah&yea=totally");
die;
Edited by SocialCloud, 30 November 2012 - 08:22 AM.
#3
Posted 30 November 2012 - 08:42 AM
i tried the above code but it is not working, it stays on the same page reg.php after successful validation.
Also on sending variables is it possible to use post method as i have 20 fields and some of them are text area fields.
#4
Posted 30 November 2012 - 08:47 AM
// Get a key from https://www.google.com/recaptcha/admin/create
$publickey = "xxxxxxxxxxxxxx";
$privatekey = "xxxxxxxxxxxxx";
# the response from reCAPTCHA
$resp = null;
# the error code from reCAPTCHA, if any
$error = null;
# was there a reCAPTCHA response?
if(isset($_POST["recaptcha_response_field"])) {
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if ($resp->is_valid) {
// if by function
RegisterUser(Your 20 variables each separated by a comma);
} else {
# set the error code so that we can display it
$error = $resp->error;
echo "Error captcha incorrect";
}
}
#5
Posted 30 November 2012 - 08:55 AM
As i said the accountcreation.php has got very complex code and moving that into a function in the reg.php is inviting more troubles i believe.
Can i store the data from all the 20 fields in a session and use them in accountcreation.php? but even for that i should be redirected to the second page, which is not working for me using the header(), is there any other way of doing it, like auto submit etc.. please think if you have any suggestions, It is bugging me for almost 2 days..
#6
Posted 30 November 2012 - 08:58 AM
#7
Posted 30 November 2012 - 09:08 AM
"In order to be irreplaceable, one needs to be different from another."
CMS Development: http://www.janedealsart.co.uk/cms/
#8
Posted 30 November 2012 - 09:08 AM
so i have a feeling that transfering all the data along with the file attachemnts is beyond by calibre now
so i'll try to move the code back to the first page...it is a tough task but doable.
php is not easy as many people say
#9
Posted 30 November 2012 - 09:10 AM
#10
Posted 30 November 2012 - 09:12 AM
#11
Posted 30 November 2012 - 09:14 AM
"In order to be irreplaceable, one needs to be different from another."
CMS Development: http://www.janedealsart.co.uk/cms/
#12
Posted 30 November 2012 - 09:26 AM
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











