close ad
Databridge V2 with MySQLi support IS Now Available!
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Trying to integrate reCAPTCHA v2

Thread began 5/24/2018 8:17 am by mrs | Last modified 5/25/2018 2:33 pm by mrs | 198 views | 8 replies |

mrs

Trying to integrate reCAPTCHA v2

Hi All, I am trying to integrate google's recapture 2 and I have been looking everywhere to figure out where I implement the secret key code for PHP but with very little success.

I've built a couple of pages with the beta version of DA. It's a call back request page where the relevant info is entered by the user, and once submitted it enters into the database and sends an email, then it goes to the detail page of the data/info entered. This all works fine both with and without the recaptcha widget in place.

What's currently happening is each time I test by not checking the recaptcha checkbox, the page is submitting anyway! I have no idea why.

Any thoughts?

I've attached my page for you to see how I've implemented the code. (FYI: The codes are dummy codes for site and secret keys that are available from google for testing.)

Attached Files
request-call-back.php
Sign in to reply to this post

Ray BorduinWebAssist

Update the webassist WA Server Validations server behavior.

Add a new non-blank validation on the value: <?php echo($succMsg); ?>

Sign in to reply to this post

mrs

Awesome, that seems to have done the job of it not submitting if the reCAPTCHA hasn't been checked. However, it has overridden any error message for the reCAPTCHA which isn't particularly UX friendly, so I am trying to add my own invalid state... but guess what... I can't make it work!

I have this for the server behaviours:

<?php
if ((isset($_POST["Insert"]) || isset($_POST["Insert_x"]))) {
$WAFV_Redirect = "".(htmlentities($_SERVER["PHP_SELF"], ENT_QUOTES)) ."?invalid=true";
$_SESSION['WAVT_requestcallback_Errors'] = "";
if ($WAFV_Redirect == "") {
$WAFV_Redirect = $_SERVER["PHP_SELF"];
}
$WAFV_Errors = "";
$WAFV_Errors .= WAValidateRQ((isset($_POST["fld_cb_title"])?$_POST["fld_cb_title"]:"") . "",true,1);
$WAFV_Errors .= WAValidateRQ((isset($_POST["fld_cb_fname"])?$_POST["fld_cb_fname"]:"") . "",true,2);
$WAFV_Errors .= WAValidateRQ((isset($_POST["fld_cb_lname"])?$_POST["fld_cb_lname"]:"") . "",true,3);
$WAFV_Errors .= WAValidateEM((isset($_POST["fld_cb_email"])?$_POST["fld_cb_email"]:"") . "",true,4);
$WAFV_Errors .= WAValidateRQ((isset($_POST["fld_cb_country"])?$_POST["fld_cb_country"]:"") . "",true,5);
$WAFV_Errors .= WAValidateRQ((isset($_POST["fld_cb_telephone"])?$_POST["fld_cb_telephone"]:"") . "",true,6);
$WAFV_Errors .= WAValidateRQ((isset($_POST["fld-cb_calltime"])?$_POST["fld-cb_calltime"]:"") . "",true,7);
$WAFV_Errors .= WAValidateRQ(($succMsg) . "",true,8);

if ($WAFV_Errors != "") {
PostResult($WAFV_Redirect,$WAFV_Errors,"requestcallback");
}
}
?>


And I have this for my validation error message:

<div class="lineGroup">
<div class="g-recaptcha" data-sitekey="qwertyuioplkjhgfdsazxcvbnm"></div>
<?php
if (ValidatedField('requestcallback','requestcallback')) {
if ((strpos((",".ValidatedField("requestcallback","requestcallback").","), "," . "8" . ",") !== false || "8" == "")) {
if (!(false)) {
?><span class="serverInvalidState" id="$succMsg">Hmmm... it seems you might be a robot! Click to prove you're not.</span><?php //WAFV_Conditional request-call-back.php requestcallback(7:)
}
}
}?>
</div>

I assume I'm missing something from the Server Validation behaviour because there seems to be nothing to tie the reCAPTCHA to the invalid state. What, I don't know though!

Just thinking on the fly as I type this, should I add a name or ID to the reCAPTCHA that can then be picked up by the WA Server Validation panel?

Thanks so far Ray.

Sign in to reply to this post

Ray BorduinWebAssist

It looks like that would work to me. I'd need a url to reproduce and FTP access to debug it.

Sign in to reply to this post

mrs

Info below for you Ray.

Are you updating the captcha facility in DA to reCAPTCHA at some point?

Thanks Ray

Sign in to reply to this post

Ray BorduinWebAssist

In your css file you have:
.serverInvalidState {
display: none;
}

but then your error message you give a class="serverInvalidState"... which means it won't be displayed. I'm not sure why that line is in your css or why you use that class for your error messages, but one or the other has to change if you want the error message to show.

Sign in to reply to this post

mrs

Sigh... I do not recall making that change but I must've done so! Such a silly, simple little thing has held me back for the best part of a day!

Thanks for that Ray.

As for the persistent checkbox feature, I have this working, so will post it here for my own reference in the future when I struggle with this again... because I will :D :

<?php if (!(strcmp((isset($_GET["invalid"])?ValidatedField("requestcallback","tnc"):""),"1"))) {echo "checked=\"checked\"";} ?>

Once again, thanks for your help on this Ray.

Because you've had a few requests on this reCAPTCHA, I will strip down my page and upload it here for others to use as reference.

Sign in to reply to this post

mrs

While I've got your attention on this particular page, how do I set persistence on the check box above the reCAPTCHA? By that I mean that if a user has clicked the checkbox, and they submit the page and there's a validation error, the check box unchecks itself again on page refresh. I was sure it was something to do the value, but it won't retain the check with what I've tried which is:

<input <?php if (!(strcmp(((isset($_POST["tnc"]))?$_POST["tnc"]:""),(ValidatedField("requestcallback","tnc"))))) {echo "checked=\"checked\"";} ?> name="tnc" type="checkbox" required="required" class="mr-2" id="tnc" tabindex="9" title="tnc">

I'm adding this to the value of the checkbox by clicking the dynamic (bind to dynamic source) button in the DW properties panel, and checking if the form post is equal to WA Validated Entries... however, it not adding as a value, it's adding as a string of PHP code outside of the value attribute!

Basically, I'm asking you how do I go about setting the checkbox to remember it's state? I was sure that's how I did it!

Sign in to reply to this post

Ray BorduinWebAssist

This post has been deleted.

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...