Jump to content

Combining two PHP scripts


ziikutv

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.