I am having trouble checking if recaptcha is checked or not in authController.php. In the signup.php page, when user submits the form, form method is post, and action = authController.php
My signup page works perfectly fine without recaptcha. Assuming I define recaptcha div correctly along with the valid secretkey on signup.php so that I don't have to put irreleant stuff here, My ONLY question is how do I check recaptha POST in authController.php. What's happening right now is that if I check or don't check recaptcha, when the form is submitted, it comes back saying recaptcha is required. If I commnent the code out, then obviously registration works.
After the signup form is submitted, I am coming back to the signup form EVEN when successful and change the REGISTER button to EMAIL SENT in green color, and disable button itself. Having said that, I think what is happening is that when the page gets reloaded, it loses track of checkmark since I am using PHP. How I know that is after submitting, checked is not checked anymore, but I think there has to be a way to use PURE php. Also then howcome First Name, Last name ... are all recognized after submitting. Kind of getting frustated now with this. Here is how I am checking if recaptcha was checked or not in authController.php file.
'''
if(empty($_POST['g-recaptcha-response']))
{
$errors[captcha_error'] = "Captcha is required";
}
else
{
$secretKey = "mykey";
$url = 'https://www.google.com/recaptcha/api/siteverify?secret='.$secretKey.'&response='.$_POST['g-recaptcha-response'];
$response = file_get_contents($url);
$response_data = json_decode($response);
if($response_data->success)
$errors['captcha_error'] = null;
}
'''
errors is array defined above, the syntax is correct. On the signup.php page, I check if errors array captcha_error is SET or NULL. This is how I know if the box was checked or not. If I HAVE to use ajax using $data and success, then how please. Please remember I using PURE php and no jquery OR AJAX (although I think I may end up using it since ajax won't reload whole page, and therefore I WONT lose the checkmark, and may be that is my problem), but PHP is preferred. Thanks
After contacting my hosting just about when I was decided to give up, the conclusion was that the "allow_url_fopen" was not checked off in my php settings. So it wasn't my code. It worked like charm after the option was checked. Not sure why it was unchecked by default in the first place, and no youtube video shows to make sure of this.
Sigh....
Hopefully, it helps other people who are struggling in same situation