# Help getting captcha working in PHP form with JS field validation

**URL:** <https://forum.kirupa.com/t/help-getting-captcha-working-in-php-form-with-js-field-validation/637193>\
**Category:** programming\
**Created:** [September 20, 2017, 12:55am UTC](https://forum.kirupa.com/t/help-getting-captcha-working-in-php-form-with-js-field-validation/637193 "2017-09-20T00:55:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![junkerjorg](https://avatars.discourse-cdn.com/v4/letter/j/9d8465/32.png) [@junkerjorg](https://forum.kirupa.com/u/junkerjorg)\
**Post date:** [September 20, 2017, 12:55am UTC](https://forum.kirupa.com/t/help-getting-captcha-working-in-php-form-with-js-field-validation/637193/1 "2017-09-20T00:55:21Z")

</div>

I have PHP form with JS field validation and I recently added the Google reCaptcha. I have everything working except when the Captcha fails I can’t get my error message to show. I’d be happy to share what I have and see if someone can guide me in the right direction.

---

<div class="post-metadata">

**Author:** ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)\
**Post date:** [September 20, 2017, 1:31am UTC](https://forum.kirupa.com/t/help-getting-captcha-working-in-php-form-with-js-field-validation/637193/2 "2017-09-20T01:31:36Z")

</div>

Absolutely! Please feel free to post the source code and/or link to your form, and one of us who sees it would be happy to take a look 🙂

---

<div class="post-metadata">

**Author:** ![junkerjorg](https://avatars.discourse-cdn.com/v4/letter/j/9d8465/32.png) [@junkerjorg](https://forum.kirupa.com/u/junkerjorg)\
**Post date:** [September 25, 2017, 9:21pm UTC](https://forum.kirupa.com/t/help-getting-captcha-working-in-php-form-with-js-field-validation/637193/5 "2017-09-25T21:21:35Z")

</div>

I put this code in and I had the CaptchaFail parsing True

```
            main('Location: contactform.php?CaptchaPass=True');

}else{

	main('Location: contactform.php?CaptchaFail=True');

```

But I also added this snippet to get my error message and when I click send it seems to error out and the screen turns white.

```
    <?php if(isset($_GET['CaptchaFail'])){ ?>
    <div class="content_item">Captcha Failed, please try again</div>
    <?php } ?>
```

---

<div class="post-metadata">

**Author:** ![junkerjorg](https://avatars.discourse-cdn.com/v4/letter/j/9d8465/32.png) [@junkerjorg](https://forum.kirupa.com/u/junkerjorg)\
**Post date:** [September 26, 2017, 8:20pm UTC](https://forum.kirupa.com/t/help-getting-captcha-working-in-php-form-with-js-field-validation/637193/6 "2017-09-26T20:20:11Z")

</div>

Latest update, I scrapped the previous method and went for something simple. I now have the following code in place and I get my Captcha error message but it seems to be always false and the message displays all the time. Now I need to figure out how to make false not show on screen until after send has been pressed.

```
       <?php if(isset($data->success)AND $data ->success == false) { 
   				echo "<h1>Captcha failed, please try again</h1>"; 
				} 
			?>
```

---

<div class="post-metadata">

**Author:** ![junkerjorg](https://avatars.discourse-cdn.com/v4/letter/j/9d8465/32.png) [@junkerjorg](https://forum.kirupa.com/u/junkerjorg)\
**Post date:** [September 26, 2017, 8:24pm UTC](https://forum.kirupa.com/t/help-getting-captcha-working-in-php-form-with-js-field-validation/637193/7 "2017-09-26T20:24:05Z")

</div>

Actually this appears to be working now! Once I left the page and returned success was no longer false so the error message went away. Tested it without checking the reCaptcha and I got the error message, then tested checking the Captcha and the Message Sent worked as expected. @kirupa
