Jump to content

Recommended Posts

I have a form script which displays $output. And I have made different vars like $output so they display for example if one types invalid email ID, it will use "$output = $invalidID". and $invalidID equals to a text saying "Invalid email provided".

 

I've added reCAPTCHA and it works fine as well. But when one types in invalid captcha, the form disappears (Captcha is between the form tags) and it says the text when wrong captcha is typed.

 

This is the captcha's code which does verification.

	require_once('captcha/recaptchalib.php');
	$privatekey = "xxxxx";
	$resp = recaptcha_check_answer ($privatekey,
	$_SERVER["REMOTE_ADDR"],
	$_POST["recaptcha_challenge_field"],
	$_POST["recaptcha_response_field"]);
	if (!$resp->is_valid) {
	die ("Invalid Captcha entered");
	}

 

So what I want to do is setup a variable called $invalidcap and set it to a text saying invalid captcha entered. And display that text in $output so that it doesn't make the form and captcha disappears and show the text "invalid captcha entered" instead shows it where I set the $output to.

 

How do I do that?

 

So in english this is what I want to do,

 

When die, make $output = $invalidcap in the display field which has the following HTML CODE

<p class="response" style="height: 1px"><?=$output?></p>

Link to comment
https://forums.phpfreaks.com/topic/172226-combining-two-php-scripts/
Share on other sites

Well what you're trying to do is this? die() exits the page, thus preventing the form from finishing etc. I'd recommend just doing this..

//Form code here... {<form>}

if (!$resp->is_valid) {
  echo '<p class="response" style="height: 1px">'.$output.'</p>';
} else { 
  echo 'Correct.';
  //do something if captcha was correct!
}

Take out the previous 'if' from the captcha code, and place this new one wherever you wish for the error to be displayed, if that's what you wanted.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.