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

Fallback on no-js #50

Closed timiwahalahti closed 5 years ago

timiwahalahti commented 7 years ago

Right now forms isn't working if used does not have javascript enabled. Yes, every website relies on js but I think when speaking about forms, it's quite important to have fallback.

We could just set form method to post, but that causes quite possibly conflict with post variable names since WordPress uses internally example name (full list of reserved variable names here.

One option is to prefix every input in code, so that user can just input name="name" in editor and it changes to name="wplf_name". But I'm not sure if this is the way to go, because it's not that pretty, causes a lot of code changes and possibly breaks custom form handling made by user.

Other option is use get method, but then you can't send files and for pretty urls we need to handle form and make a redirect after that without any parameters.

And there's also a small problem with how and when to indicate success, using get parameter isn't a option because then user sends that url to friend... Yes, post parameter is answer. But we need also think form validation and validation error messages.

Yrgh :/

k1sul1 commented 7 years ago

$0.02:

We could embed that list of reserved variable names on the editor screen, so that users at least know about it. Another option would be not to bug them about it, until they use a reserved word => tell the user what went wrong and how to fix.

Prefixing is BS, and I'm pretty sure no one wants that.

Success / Failure could be indicated with redirection to a user created thank you page.

timiwahalahti commented 7 years ago

I was a bit in a hurry and needed some solution quikly, so I made some rough and nasty changes...

Added also this few lines of code to the theme

function timiwahalahti_wplf_nojs_submit() {
  if( isset( $_POST['timiwahalahti-name'] ) ) {
    wplf_ajax_submit_handler( true );
    $_POST['_wplf_success'] = true;
  }
}
add_action( 'init', 'timiwahalahti_wplf_nojs_submit' );

So this does not make use of any proper validation for required fields and relies that user has prefixed input names, but it works as a dirty solution for now. Something more subtle is needed at least in some point.

k1sul1 commented 5 years ago

Closing, as a PR for this already exists.