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

Validation Message never Displayed #32

Closed janwidmer closed 5 years ago

janwidmer commented 5 years ago

Hi there, I just installed your addon and it works very well, thank you! One thing that I noticed is, that I never get the validation message when I do not solve the captcha.

My settings:

My Form Logic:

$scriptProperties['hooks'] = 'recaptchav2,email';
$scriptProperties['validate'] = 'g-recaptcha-response:required';
$scriptProperties['g-recaptcha-response.vTextRequired'] = 'ReCaptcha Validation Message';
$modx->runSnippet('FormIt', $scriptProperties);

My Form Template:

<div class="g-row layout-responsive-form row-form[[!+fi.error.recaptchav2_error:notempty=` row-form-error`]]">
    [[!recaptchav2_render]]
    [[!+fi.error.recaptchav2_error:notempty=`
        <div class="field-msgs">
            <div class="error">
                [[!+fi.error.recaptchav2_error]]
            </div>
        </div>
    `]]
</div>

Any idea what I am doing wrong?

sepiariver commented 5 years ago

Hi @janwidmer glad you like it. Does the validation error show if you use the placeholder without any filters? Only:

[[!+fi.error.recaptchav2_error]]

Also you don’t have to add it to the FormIt validators: it’s always required. In fact try if removing it from the validation helps with the issue.

sepiariver commented 5 years ago

Also looks like you’re doing this inside another Snippet. Without seeing what that Snippet is doing I can’t be certain of how the placeholders and hook execution might be affected

janwidmer commented 5 years ago

I removed it from the validators and also removed the filter, but I still don't get any errors.. In the modx logs, I get the following entry, no matter if I solve the captcha before submitting or not..

Could not load FormItReCaptcha service class.

I am using a pattern setup where I am using a snippet and a chunk for every pattern. The snippet contains the above logic and the call to the chunk:

$scriptProperties = array();
$scriptProperties['hooks'] = 'recaptchav2,email';

$modx->runSnippet('FormIt', $scriptProperties);
$output = $modx->getChunk('mod-form',array());

return $output;

Of course, that could have something to do with it, but all other formit things work perfectly including custom hooks..

sepiariver commented 5 years ago

Oh! That is a current bug in FormIt: it does a strpos check for “recaptcha” in the hooks and if so, attempts to load the legacy recaptcha that was built into FormIt.

There’s a hotfix for it somewhere...

Which version of FormIt are you using?

janwidmer commented 5 years ago

I just upgraded to FormIt version 4.1.1

sepiariver commented 5 years ago

It's a known issue at FormIt. See:

https://github.com/Sterc/FormIt/issues/170

https://github.com/Sterc/FormIt/pull/193

sepiariver commented 5 years ago

@janwidmer you can copy the hotfix from that FormIt PR referenced above into the file in your install.

(good idea to backup the filesystem before making such changes in core/)

janwidmer commented 5 years ago

@sepiariver and that known issue will also fix the validation message not being displayed?

sepiariver commented 5 years ago

Yes @janwidmer because currently FormIt is trying to load the legacy built-in recaptcha class and throwing an error. This message Could not load FormItReCaptcha service class. is not from the RecaptchaV2 Extra, it's from FormIt.

janwidmer commented 5 years ago

ah ok thanks :-)

janwidmer commented 5 years ago

Hey..I am sorry to bring this up again..I just updated to the newest FormIt Version 4.2.1 which includes the fix for the ticket you mentioned above.. I am running on recaptchav2 Plugin Version 3.0.1-rc1, but that did not fix my problem..the error message in the log is gone, but I still do not get a validation message when not solving the captcha..

I created a very simple test case which just contains the below code directly in the content field of a test page (without using my pattern framework). You can see the page here: https://www.widmer-web.ch/test-page.html

[[!FormIt?
    &hooks=`recaptchav2`
    &validate=`test:required`
]]

<form action="[[~[[*id]]]]" method="post" id="test-form">
    <label for="test">Test Field</label>
    <input type="text" value="[[!+fi.test]]" name="test"  id="test" />
    [[!+fi.error.test]]

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

    <button type="submit">Submit Form</button>
</form>

As you can see when submitting, the error message of the required test field gets outputtet, but no recaptcha error message..

any idea, what I am doing wrong?

janwidmer commented 5 years ago

ok seems to work now.