WebsiteBaker Community Forum

WebsiteBaker Support (2.12.x) => General Help & Support => Topic started by: dbs on January 16, 2019, 06:16:54 PM

Title: mpForm required
Post by: dbs on January 16, 2019, 06:16:54 PM
Hello, have used the search but found not the right posts.
I want to use the "required" attribute in the data/input fields to prevent the page from reloading if the user has forgotten something.

If this has already been discussed, a link to it would be nice.
Is that possible at all?
Title: Re: mpForm required
Post by: Martin Hecht on January 16, 2019, 09:08:59 PM
I think this has not yet been discussed. mpForm allows to mark some fields as required, but it does not (yet) make use of the "required" attribute in the input tag. If "required" fields are not filled in, an error message is displayed, and the user is presented the form again.
Perhaps it's a good idea to add this attribute to the input field as well and let the browser handle it. Older older browsers that don't support html 5 (if at all relevant today) would probably ignore it, so the current check on the server side would apply, and all browsers that understand the required attribute enforce the required fields being filled in for the first submission attempt already.
Title: Re: mpForm required
Post by: Martin Hecht on January 23, 2019, 09:06:36 PM
I have just released version 1.3.26 on Github  (https://github.com/WebsiteBaker-modules/mpform/releases/tag/1.3.26)which implements the requested feature.

Currently, there are two exceptions:
- Checkboxes can't be made "required" at least not checkboxes in a group (otherwise the user can *only* select all of them, and the browser would refuse to submit any other choices), and
- the Captcha (which would require a modification in the core (either implement the requested feature, maybe as an additional option, or the feature not to display the captcha fields already but return the html code in a variable instead of sending it directly to the client).
Title: Re: mpForm required
Post by: dbs on January 23, 2019, 11:03:44 PM
Nice. Death to the reloading pages.  :-)
In the next WB Fix the captcha will have 'required' too.

The checkboxes still remain. Have experimented with javascript, but no 100% result yet.
Title: Re: mpForm required
Post by: Martin Hecht on January 24, 2019, 01:21:36 PM
Well, apart from required fields not filled in, there are other error scenarios which still require that the form is shown to the user once more (e.g. uploading files of unsupported type, uploading too large files, supply a string as an email-Address which does not meet the criteria of being an email address, etc.). And, not to forget: Although most clients support the required-attribute nowadays, the validation on the server should not rely on a particular feature of the client. A malicious user could send manipulated data where some required fields are missing deliberately. If fields are made "required" the form has to ensure that in successful submissions these fields are at least filled in "somehow", and we have to double check this on the server side. Further validation of the data is possible in the user-defined functions by the way.

Anyhow, I understand the argument of convenience for the end-user, and therefore I have implemented this feature. I just wanted to point out that we can not avoid the reloading pages completely. We need them for cases in which server-side checks fail on the inserted data.

About the checkboxes: Probably one would have to create a js function for each checkbox group that clears the required attribute on all other checkboxes of the same group as soon as one of them is selected (and adds it again when the last one is unchecked) and assign it to the onchange event.
Title: Re: mpForm required
Post by: Martin Hecht on February 12, 2019, 09:55:50 PM
I forgot the date fields. They are checked on the client side in Version 1.3.28 (https://github.com/WebsiteBaker-modules/mpform/releases/tag/1.3.28) now.