libreform / wp-libre-form

Easy native HTML5 forms for WordPress. Version 1.5 is unmaintained, but works without issue. 2.0 has been rewritten from the ground, and can be found at https://github.com/libreform/libreform
https://wordpress.org/plugins/wp-libre-form
GNU General Public License v3.0
67 stars 27 forks source link

Add no-jos fallback #63

Closed timiwahalahti closed 7 years ago

timiwahalahti commented 7 years ago

As discussed in #50, this implements quite simple fallback to handler when submitting form without javascript. It can be turned on with filter.

Because some terms are reserved for WordPress core, this PR also implements check for those in fallback mode and shows error when using those terms as input names.

After successful form handling user is redirected to referrer page and thank you message is shown instead of form. When validation contains errors, message from validator is shown below form the same way as with javascript. Only downside is that inputs are cleared :/ But I think we can accept that, because browsers supports input checks quite widely. Can we?

Needs a bit more testing, updates to README and opinion about success/error handling.

anttiviljami commented 7 years ago

This didn't work out of the box for me. Do I need to resave my form or something first? I just got a 404 after submitting, and weirdly the form method was GET instead of POST

timiwahalahti commented 7 years ago

Tested my branch with clean install and it worked.

404 after submit is probably because you have field named name which is reserved for WP core. When you go to form editor with nojs fallback enabled (add_filter( 'wplf_form_nojs_fallback', '__return_true' );), warning about this is shown. Maybe default name field name should be changed... Method is POST only if nojs fallback is enabled.

Just noticed that success/error messages wont work if site uses default permalink structure, will fix that if (and when 😝) PR is otherwise approved.

anttiviljami commented 7 years ago

I must have screwed up the merge somehow. Can you rebase to master and force-push so I can test? :)

timiwahalahti commented 7 years ago

Sometimes I really hate git :D Going to close this PR and make new with different branch.