mpForm required

Martin Hecht

I forgot the date fields. They are checked on the client side in Version 1.3.28 now.

Martin Hecht

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.

dbs

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.
[url="https://onkel-franky.de"]https://onkel-franky.de[/url]

Martin Hecht

I have just released version 1.3.26 on Github 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).

Martin Hecht

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.

dbs

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?
[url="https://onkel-franky.de"]https://onkel-franky.de[/url]