sepiariver / recaptchav2

Google's ReCaptcha V2 + V3 for MODX CMS: https://sepiariver.com/modx/recaptchav2-supports-recaptchav3/
https://sepiariver.com/
GNU General Public License v2.0
21 stars 15 forks source link

MODX FormIt page refreshes without submitting form - rcaptchav2 #5

Closed rjohnson375 closed 8 years ago

rjohnson375 commented 8 years ago

(the code preview is contained in backticks)

[[!FormIt? &hooks=recaptchav2,spam,email,redirect &emailTpl=vipEmail &emailSubject=Submission via VIP form &emailTo=robert@domain.com &emailFrom=fromemail@domain.com &redirectTo=1169 &validate=firstName:required:minLength=^2^, lastName:required:minLength=^2^, address1:required, city:required, zipcode:required:minLength=^5^, phone:required, state:required, emailAddress:required ]]

<form action="[[~[[*id]]]]" method="post" id="vipForm" name="vipForm"> . . . [[!recaptchav2_render]] [[!+fi.error.recaptchav2_error]] </form>

[[!+fi.error.firstName:notempty=`Please enter a valid first name.`]]
[[!+fi.error.lastName:notempty=`Please enter a valid last name.`]]
[[!+fi.error.address1:notempty=`Please enter a valid address.`]]
[[!+fi.error.city:notempty=`Please enter a valid city.`]]
[[!+fi.error.zipcode:notempty=`Please enter a valid zip code.`]]
[[!+fi.error.state:notempty=`Please select a valid state.`]]
[[!+fi.error.phone:notempty=`Please select a home phone number.`]]
[[!+fi.error.emailAddress:notempty=`Please enter a valid email address.`]]

sepiariver commented 8 years ago

Hi could you please post the entire contents of the chunk or template where this form is? And also mention if it's a chunk or template.

You may have posted the whole thing but it got mangled by the Markdown. If that's the case maybe attach a file with the content?

rjohnson375 commented 8 years ago

It's a resource, does it have to be in a chunk? Wouldn't that be a quick solution... ;)

rjohnson375 commented 8 years ago
```
[[!FormIt? &hooks=`recaptchav2,spam,email,redirect` &emailTpl=`vipEmail` &emailSubject=`Submission via VIP form` &emailTo=`robert@domain.com` &emailFrom=`reply@domain.com` &redirectTo=`1169` &validate=`firstName:required:minLength=^2^, lastName:required:minLength=^2^, address1:required, city:required, zipcode:required:minLength=^5^, phone:required, state:required, emailAddress:required` ]] < form action="[[~[[*id]]]]" method="post" id="vipForm" name="vipForm">
First Name*
Last Name*
Home Address*
City*
State*
ZIP Code*
Home Phone*
Mobile Phone
Email*

Place a checkmark next to how you would
like to be notified of service

Account Number
  [[!recaptchav2_render]] [[!+fi.error.recaptchav2_error]]
```
```
```

[[!+fi.error.firstName:notempty=`Please enter a valid first name.`]]
[[!+fi.error.lastName:notempty=`Please enter a valid last name.`]]
[[!+fi.error.address1:notempty=`Please enter a valid address.`]]
[[!+fi.error.city:notempty=`Please enter a valid city.`]]
[[!+fi.error.zipcode:notempty=`Please enter a valid zip code.`]]
[[!+fi.error.state:notempty=`Please select a valid state.`]]
[[!+fi.error.phone:notempty=`Please select a home phone number.`]]
[[!+fi.error.emailAddress:notempty=`Please enter a valid email address.`]]

rjohnson375 commented 8 years ago

New issue, now checking the box for "I am not a robot", it just switches to green checkmark without image verification

sepiariver commented 8 years ago

Hi Robert,

Regarding your most recent comment, RecaptchaV2 does that if it already knows you're not a robot. It stores your previous responses to recaptcha, thus making it quite a bit less frustrating for humans.

I haven't had a chance to test out your code yet, but one thing to check if you don't mind, is that you have 'allow_url_fopen' enabled in your php.ini. You can check by going to Manage -> Reports -> System Info in the MODX Manager and doing a browser search for 'allow_url_fopen'. Here's a screenshot:

screen shot 2015-11-05 at 11 46 46 pm

If you do not have it enabled, it explains the problem and there's a fix coming in the next version. If it IS enabled, then it's something else and I'll have to test out your code.

rjohnson375 commented 8 years ago

I just verified that allow_url_fopen is on. I am going entry by entry and testing the code next, and still not finding anything, hopefully a second set of eyes will help. Thank you.

sepiariver commented 8 years ago

I just updated the package to version 2.0.0-rc1. Could you please try updating RecaptchaV2 to the latest and let me know if it works?

Also, regarding your specific issue, it's the fact that your markup isn't valid. You have hanging div tags inside your form element. This works, for example:

<div id="content">
    <div id="formbox">

        <div id="formtable">

[[!FormIt?
&hooks=`recaptchav2`
]]

        <form action="[[~[[*id]]]]" method="post" id="vipForm" name="vipForm">
        <div>
            <table cellspacing="0" cellpadding="0" border="0" width="900" >
                <tr>
                    <td align="left" width="450">First Name* <br />
                    <input value="[[!+fi.firstName]]" class="inputbox" size="50" id="firstName" type="text" name="firstName" maxlength="100" />
                    </td>
                    <td align="left"  width="450px">Last Name* <br />
                    <input value="[[!+fi.lastName]]" class="inputbox" size="50" id="lastName" type="text" name="lastName" maxlength="100" />
                    </td>
                </tr>
                <tr>
                    <td align="left" width="450">Home Address* <br />
                    <input value="[[!+fi.address1]]" class="inputbox" size="50" id="address1" class="fullwidth" type="text" name="address1" maxlength="100" />
                    </td>
                    <td align="left" width="450">City*<br />
                    <input value="[[!+fi.city]]" class="inputbox" size="50" id="city" class="inputbox" type="text" name="city" style="width: 340px;" maxlength="50" />
                    </td>
                </tr>
                <tr>
                    <td align="left"  width="450">State*<br />
                        <!-- <input id="state" class="inputbox" type="text" name="state" size="50" value="" /> -->
                        <input value="[[!+fi.state]]" id="state" class="inputbox" type="text" name="state" maxlength="2" style="width: 50px;" />
                    </td>
                    <td align="left" valign="middle" width="450">ZIP Code*<br />
                    <input value="[[!+fi.zipcode]]" size="50" class="inputbox" id="zipcode" class="inputbox" type="text" name="zipcode" maxlength="5" style="width: 77px;" />
                    </td>
                </tr>
                <tr>
                    <td align="left"  width="450">Home Phone*<br />
                    <input value="[[!+fi.phone]]" class="inputbox" size="50" id="phone" class="fullwidth" type="text" name="phone" maxlength="20" />
                    </td>
                    <td align="left"  width="450">Mobile Phone<br />
                    <input value="[[!+fi.mobilePhone]]" class="inputbox" size="50" id="mobilePhone" class="fullwidth" type="text" name="mobilePhone" maxlength="20" />
                    </td>
                </tr>
                <tr>
                    <td align="left" width="450">Email* <br />
                    <input value="[[!+fi.emailAddress]]" class="inputbox" size="50" id="emailAddress" class="fullwidth" type="text" name="emailAddress" maxlength="65" />
                    </td>
                    <td align="left" width="450">

                        <input type="hidden" name="customer[]" value="" />
                        <input id="currentCustomer" class="selectbox" type="checkbox" name="customer[]" value="Yes" [[!+fi.notify:FormItIsChecked=`Yes`]] />
                        <label for="currentCustomer">Yes</label>
                        <input id="notCurrentCustomer" class="selectbox" type="checkbox" name="customer[]" value="No" [[!+fi.notify:FormItIsChecked=`No`]] />
                        <label for="notCurrentCustomer">No</label>
                    </td>
                </tr>
            </table>
        </div> <!-- id="formtable" -->

        <div id="checkbox">
            <table cellspacing="0" cellpadding="0" border="0" width="900">
                <tr>
                    <td align="left" valign="middle" width="450">
                        <p class="purple">Place a checkmark next to how you would <br/>like to be notified of service</p>
                        <input type="hidden" name="notify[]" value="" />
                        <input id="notifyPhone" class="selectbox" type="checkbox" name="notify[]" value="Phone" [[!+fi.notify:FormItIsChecked=`Phone`]] />
                        <label for="notifyPhone">Phone</label>
                        <input id="notifyEmail" class="selectbox" type="checkbox" name="notify[]" value="Email" [[!+fi.notify:FormItIsChecked=`Email`]] />
                        <label for="notifyEmail">Email</label>
                        <input id="notifySnailMail" class="selectbox" type="checkbox" name="notify[]" value="snailMail" [[!+fi.notify:FormItIsChecked=`snailMail`]] />
                        <label for="notifySnailMail">Snail Mail</label>
                    </td>       
                    <td align="left" width="450">Account Number <br />
                    <input value="[[!+fi.account]]" class="inputbox" size="50" id="account" class="fullwidth" type="text" name="account" maxlength="20" />
                    </td>
                </tr>
                <tr>
                    <td align="left" valign="middle" width="450">
                        &nbsp;
                    </td>
                    <td width="450">

[[!recaptchav2_render]]
[[!+fi.error.recaptchav2_error]]

                        <input id="submit" class="submitBtn" type="submit" name="submit" value="test"/>
                    </td>
                </tr>
            </table>
        </div> <!-- id="checkbox" -->
        </form>
        </div><!--/#formtable-->
    </div> <!-- id="formbox" -->
</div> <!-- id="content" -->

Hope this helps,

rjohnson375 commented 8 years ago

I am so sorry, thank you for seeing that, I took this off an old Joomla version of the site and have been staring at it too long. Thank you very much, it is working perfectly