billythekid / recaptchaguest

Plugin to allow the use of the matt-west/craft-recaptcha (craft2 version aberkie/craft-recaptcha) in Guest Entries submissions
MIT License
4 stars 2 forks source link

Form not reloading on recaptcha fail #1

Closed alisonweirsmith closed 4 years ago

alisonweirsmith commented 4 years ago

Hi,

I'm running an old Craft 2 site and have installed the three plugins as per the instructions (as far as I can see).

However, when the recaptcha field is not completed, the form does not render with errors. It just loads the contact page with no form at all. I need to be able to give users a "second chance" as it were to complete the captcha.

Here is the site (test server) https://test.runwildstudio.co.nz/theskicompany.

You can get to the form by clicking the "Enquire" menu item.

Regards Alison

billythekid commented 4 years ago

Hi Alison,

I've tried to test the form a couple of times on that site but just get a CSRF error, with or without the captcha being ticked.

Can you paste your twig code here and I'll see if I can spot anything with that. It sounds like a logic issue in the template as the plugin doesn't handle loading the actual forms or anything.

Happy to take a look and try to replicate myself though.

Thanks

alisonweirsmith commented 4 years ago

Thanks.

There is a lot of code... Twig files here:

https://drive.google.com/open?id=1IZFEHt3_vsEEII3IvySUq_3XIklwyR5B

On Mon, 7 Oct 2019 at 21:35, Billy Fagan notifications@github.com wrote:

Hi Alison,

I've tried to test the form a couple of times on that site but just get a CSRF error, with or without the captcha being ticked.

Can you paste your twig code here and I'll see if I can spot anything with that. It sounds like a logic issue in the template as the plugin doesn't handle loading the actual forms or anything.

Happy to take a look and try to replicate myself though.

Thanks

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/billythekid/recaptchaguest/issues/1?email_source=notifications&email_token=AHNP2GFAMBQ7MGMXNJYXTNDQNLYDJA5CNFSM4I56CUQ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEAPOLEY#issuecomment-538895763, or mute the thread https://github.com/notifications/unsubscribe-auth/AHNP2GFVGPUHQO4H2JNC7LTQNLYDJANCNFSM4I56CUQQ .

billythekid commented 4 years ago

Thanks Alison,

Downloaded and installing on a fresh craft2 install, will get back to you ASAP

alisonweirsmith commented 4 years ago

Thanks. If you need a full backup of the site, please let me know.

On Mon, 7 Oct 2019 at 10:08 PM, Billy Fagan notifications@github.com wrote:

Thanks Alison,

Downloaded and installing on a fresh craft2 install, will get back to you ASAP

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/billythekid/recaptchaguest/issues/1?email_source=notifications&email_token=AHNP2GHZPHUV4JKO2NHQVEDQNL4BLA5CNFSM4I56CUQ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEAPRPTY#issuecomment-538908623, or mute the thread https://github.com/notifications/unsubscribe-auth/AHNP2GG5XWR5OHERWKJ4P33QNL4BLANCNFSM4I56CUQQ .

billythekid commented 4 years ago

Hi Alison,

I've installed a vanilla Craft (v 2.7.10) and the correct (craft 2) versions of the guestentries, recaptcha and recaptchaguest plugins. I added bootstrap 3 and some styling for errors etc just to make it a bit clearer what's happening in the form layout:

      label,
      input:not([type=checkbox]),
      textarea {
        display: block;
        margin-bottom: 1rem;
      }

      .errors, .error {
        background: pink;
        color: darkred;
        padding: 0.5rem;
        margin-top: 0.5rem;
      }

I've used your contactform template in a very simple twig page at /enquire:

{% extends "_layout" %}

{% block content %}
  {% include "pieces/contactform" %}
{% endblock %}

(Note: the label elements on that form need an equals sign between for attribute and the attribute value, e.g. <label for="contactName">Name</label>)

And this page at /thankyou:

{% extends "_layout" %}

{% block content %}
  <p>Thanks for your submission</p>
{% endblock %}

I've also set up a guest entries section in the back end and set the admin account to be the 'guest' account to save these. I've recreated your fields and made everything bar the sign up checkbox a required field in this section. The title is automatically generated using {contactEmailAddress} - {subject} to avoid not saving issues because of no title.

I've set up the google recaptcha keys in the recaptcha plugin.

So, now when I load the /enquire page I get the form displayed no problem. If I submit without filling in the captcha I get this:

Screenshot 2019-10-07 at 10 21 17

See how the recaptcha error code is showing and the form shows fine? (This isn't happening for you I take it?)

If I tick the recaptcha (but leave the other fields empty) I get this:

Screenshot 2019-10-07 at 10 21 57

So the recaptcha validated but the entry still failed, of course. Finally when I fill in everything required I get a redirect to /thankyou and see this:

Screenshot 2019-10-07 at 10 22 48

Checking the back end for the entry it's saved fine:

Screenshot 2019-10-07 at 10 23 31

So using your form code I'm not getting any issues with the form or the validation messages and indeed it loads every time as expected. The code you initially sent in the google drive doesn't have the parent of the form (the page that's including it) so perhaps the issue is on that template?

I'm happy to try to debug this further for you but it does appear that there's no issue with the plugins as they stand.

Cheers Billy

alisonweirsmith commented 4 years ago

Interesting. Ok. Yeah - it’s the failed recaptcha but form filled in correctly that gives me a blank page. So fill in the form but don’t tick the box.

On Mon, 7 Oct 2019 at 10:43 PM, Billy Fagan notifications@github.com wrote:

Hi Alison,

I've installed a vanilla Craft (v 2.7.10) and the correct (craft 2) versions of the guestentries, recaptcha and recaptchaguest plugins. I added bootstrap 3 and some styling for errors etc just to make it a bit clearer what's happening in the form layout:

  label,
  input:not([type=checkbox]),
  textarea {
    display: block;
    margin-bottom: 1rem;
  }

  .errors, .error {
    background: pink;
    color: darkred;
    padding: 0.5rem;
    margin-top: 0.5rem;
  }

I've used your contactform template in a very simple twig page at /enquire:

{% extends "_layout" %}

{% block content %} {% include "pieces/contactform" %} {% endblock %}

(Note: the label elements on that form need an equals sign between for attribute and the attribute value, e.g. <label for="contactName">Name)

And this page at /thankyou:

{% extends "_layout" %}

{% block content %}

Thanks for your submission

{% endblock %}

I've also set up a guest entries section in the back end and set the admin account to be the 'guest' account to save these. I've recreated your fields and made everything bar the sign up checkbox a required field in this section. The title is automatically generated using {contactEmailAddress} - {subject} to avoid not saving issues because of no title.

I've set up the google recaptcha keys in the recaptcha plugin.

So, now when I load the /enquire page I get the form displayed no problem. If I submit without filling in the captcha I get this:

[image: Screenshot 2019-10-07 at 10 21 17] https://user-images.githubusercontent.com/330170/66300907-09747b80-e8ee-11e9-9164-2be85288c614.png

See how the recaptcha error code is showing and the form shows fine? (This isn't happening for you I take it?)

If I tick the recaptcha (but leave the other fields empty) I get this:

[image: Screenshot 2019-10-07 at 10 21 57] https://user-images.githubusercontent.com/330170/66301015-39bc1a00-e8ee-11e9-8635-33ad0558b78c.png

So the recaptcha validated but the entry still failed, of course. Finally when I fill in everything required I get a redirect to /thankyou and see this:

[image: Screenshot 2019-10-07 at 10 22 48] https://user-images.githubusercontent.com/330170/66301082-58221580-e8ee-11e9-896e-9339867dcfcf.png

Checking the back end for the entry it's saved fine:

[image: Screenshot 2019-10-07 at 10 23 31] https://user-images.githubusercontent.com/330170/66301110-6708c800-e8ee-11e9-9f6d-76b989d6032c.png

So using your form code I'm not getting any issues with the form or the validation messages and indeed it loads every time as expected. The code you initially sent in the google drive doesn't have the parent of the form (the page that's including it) so perhaps the issue is on that template?

I'm happy to try to debug this further for you but it does appear that there's no issue with the plugins as they stand.

Cheers

Billy

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/billythekid/recaptchaguest/issues/1?email_source=notifications&email_token=AHNP2GBNQCNTXLUHL2DI6BLQNMACJA5CNFSM4I56CUQ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEAPUZLQ#issuecomment-538922158, or mute the thread https://github.com/notifications/unsubscribe-auth/AHNP2GAGUNM7OU54B3AG2CLQNMACJANCNFSM4I56CUQQ .

billythekid commented 4 years ago

Good point, I never did that in my test. However it also worked as expected. Here's what got reloaded for me doing that:

Screenshot 2019-10-07 at 11 12 51
alisonweirsmith commented 4 years ago

Thanks Billy,

I'll see what I can do to find the issue, since it's obviously on my side. I'm using Postmaster to do the sending, perhaps it's something to do with that.

On Mon, 7 Oct 2019 at 23:13, Billy Fagan notifications@github.com wrote:

Good point, I never did that in my test. However it also worked as expected. Here's what got reloaded for me doing that:

[image: Screenshot 2019-10-07 at 11 12 51] https://user-images.githubusercontent.com/330170/66303679-75a5ae00-e8f3-11e9-9a22-15306d0b56f2.png

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/billythekid/recaptchaguest/issues/1?email_source=notifications&email_token=AHNP2GCL5V72E6NUA4TLJTTQNMDWHA5CNFSM4I56CUQ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEAPX3BA#issuecomment-538934660, or mute the thread https://github.com/notifications/unsubscribe-auth/AHNP2GAIMSXCKYOLLTM42X3QNMDWHANCNFSM4I56CUQQ .

billythekid commented 4 years ago

Thanks Alison,

I'll close this issue for now but please reopen if you find something more or some incompatibility with this plugin and I'll see if I can address it. Let me know how you get on in your sleuthing!

Cheers

alisonweirsmith commented 4 years ago

Hi Billy,

I figured it out... I was being an idiot - The contact form was included in my Body matrix... Which wasn't called on the contactForm entry type... I just had to add a conditional to show the contact form is the entry type was the failed form submission. (Facepalm)

That's what I get for trying to be smart and giving clients WAYYYY too much flexibility.

On Tue, 8 Oct 2019 at 23:11, Billy Fagan notifications@github.com wrote:

Thanks Alison,

I'll close this issue for now but please reopen if you find something more or some incompatibility with this plugin and I'll see if I can address it. Let me know how you get on in your sleuthing!

Cheers

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/billythekid/recaptchaguest/issues/1?email_source=notifications&email_token=AHNP2GDH4HRX3JCMYD2I5CTQNRMDRA5CNFSM4I56CUQ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEATU52A#issuecomment-539447016, or mute the thread https://github.com/notifications/unsubscribe-auth/AHNP2GFX5PXXE7G7QLJJ7ULQNRMDRANCNFSM4I56CUQQ .

billythekid commented 4 years ago

Haha, at least you've gotten it sorted out now.

Yeah the most my clients get with forms is a lightswitch to "Show contact form"

I habitually change the guestentry variable to guestentry (instead of entry) too, to avoid confusion.

Glad you're fixed! Thanks for the update.