FormIt Contact Form Not Working After Update to PHP 8.4 & MODx3.2.4

Summary

Quick summary what this issue is about.

Step to reproduce

How to reproduce the issue, including custom code if needed.

Observed behavior

Error observed regarding the Recaptcha_Render snippet that was appearing whenever the page with the contact form was loaded. Found a fix.. but the form in general is not sending or redirecting. Still investigating but wondering if anyone else has had issues? I know this is related to the 3.2.4 update because the form sucessfully worked last week.. just prior to my update to PHP 8.4 and MODx 3.2.4

Expected behavior

How it should behave after following the steps above.

Environment

MODX version tagged when creating the issue, Apache or NGINX with version, MySQL version, browser, etc. Any relevant information.

Is it a timing issue? i.e. if you send within two minutes, does it work? Do you have the bit of code that shows if there’s an error with the recaptcha?..

[[!+fi.error.recaptchav3_error]]

Thank you for responding. I am using Zurb Foundation’s form and I have the following to handle the error. I am using v2 Extra from SepiaRiver.

The code is occurring on line 48 of the snippet recaptcha2_render.

PHP warning: Undefined variable $hook

if ($hook) {

This is from my FormIt

&hooks=\`recaptchav2,spam,FormItSaveForm,email,redirect\`

This is the code in the snippet.

$props = array_merge($scriptProperties, \[
'site_key' => $site_key,
'lang' => $lang,
'form_id' => $form_id,
\]);
$recaptcha_html = $modx->getChunk($tpl, $props);

if ($hook) {
$hook->setValue('recaptchav2_html', $recaptcha_html); // This won't re-render on page reload there's validation errors
return true;
} else { // This works at least
return $recaptcha_html;
}

The error in the dashboard occurs when the form loads, and is not related to hiting the send or even filling out the captchaV2. Initially — I was getting the images, but now it’s just the prove your human checkbox. Recaptcha has always been a pickle to work with, and I find them very frustrating in general. Is there another method of combating the spam that does not include Google?

Yes. hCaptcha. FriendlyCaptcha and a host of others. Investigating and will follow up if I find something that works. Thank you.

I’d be inclined to switch to recaptcha V3 anyway. Then maybe think about using Akismet or Cleantalk. Both are paid but have supporting MODX Extras

I found Form Protection for MODx from Jay Gilmore and loaded it. Thought I would try that route. Although… just wondering about when or how to generate the toke. Also, curious as to whether I need workemail:blank, (the honey pot trap for bot) or the text:stripTags`. I “think” that stripTags has been incorporated in current version of FormIt, so maybe not.

Got everything in place with Form Protection for MODx… set up the formit.spam_time_secret, and…

The good news is that after removing the ReCaptchaV2… not getting anymore errors in the MODx error console.

The bad news, the form does not submit, or go to the redirect page. Also… does not go the spam alert redirect that I set up.

I’m re-reviewing my code to see if I made mistakes with coding. Has anyone been able to make this work with their formit form?


[[!FormIt?
&preHooks=`generateTimeTokenHook`
&hooks=`formProtectionHook,FormItSaveForm,email,redirect`
&spamTimeThreshold=`5`
&spamWordPatterns=`viagra,crypto,free offer`
&spamEmailPatterns=`.ru,spammer.com`
&rateLimit=`1`
&rateLimitSeconds=`30`
&rateLimitCookieName=`threshold_token`
&rateLimitMaxSubmissions=`10`
&rateLimitSubmissionInterval=`3600`
&formName=`myForm`
&formFields=`comments,firstName,lastName,email,phone`
&emailTpl=`contactForm_message`
&emailFrom=`[email protected]`
&emailTo=`[email protected]`
&emailSubject=`Website message from: [[+firstName]] [[+lastName]]`
&emailReplyTo=`[[+email]]`
&redirectTo=`7`
&spamRedirectResourceId=`563`
&validate=`firstName:required,
lastName:required,
email:email:required,
phone:required,
]]

[[!+fi.error_message:notempty=`<p>[[!+fi.error_message]]</p>`]]

<!--Code for handling required fields.-->

<input type="hidden" name="form_time_token" value="[[!+fi.form_time_token]]"/>

<!--My Form fields are here. Some I have set to be Required.-->


  <div class="medium-4 columns">
      <button class="small button expand" name="Send" type="submit">SEND MESSAGE</button>
  </div>
</div>

</form>

Thought I had it figured out with a missing backward apostrophe… but now

When I hit send, the completed form remains on the screen with a message above that reads:

THERE WAS AN ISSUE WITH YOUR SESSION. PLEASE REFRESH THE PAGE AND TRY SUBMITTING THE FORM AGAIN.

After I refresh the page the completed form STILL remains in view (no redirect), with a message that reads:

YOU JUST SUBMITTED THIS FORM SUCCESSFULLY. PLEASE WAIT A WHILE BEFORE SUBMITTING AGAIN.

However… no email ever arrives in the IN Box.

:frowning:

MODx error log just has the following each time I guess I hit send, and then refresh.

Time token hash validation failed
Rate limit exceeded: Per-request delay.

Did you create a system setting for or can you see the following setting?..

formit.spam_time_secret

If it’s not there, create it and add a long string of letters and numbers - like a password

I was able to solve it. I did have a missing backward tick mark, but the form still did not work.

Then I followed an important philosphy: If all else fails, read directions. Did this, and realized that after installing, and setting everything up, I forgot to flush the cache. Doing so resulted in the form successfully being submitted followed by the page redirect.

The form mail did go to myjunk mail, but I resolved this by setting up a DMARC.

So far so good, and I have to say — so nice to not have to force people to pick out the squares with a bicycle in it.

Thank you for jumping in to help troubleshoot.