The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Empty Form Field Validation? Reply To: Empty Form Field Validation?


if I left forename blank I would see : Enter your forename Enter your surname Enter a username Enter a password Enter a valid email address

And not just : Enter your forename.

When I leave the “forename” field blank (and fill in all the other fields correctly), I see only the “Enter your forename” message. Other combinations of missing/invalid fields also produce the expected messages. Are you using this exact code? Do all the field names in your html form match those in the code?

I want to position the error messages in their respective fields in the form.

So, you want the errors (if any) to be displayed next to the form input?

Just by way of anticipation, would you also want correct inputs to be populated automatically (so the user doesn’t need to re-type everything)?

We can modify the code to use two arrays: one for error messages, and one for valid values. When we get back to the html form, we check each array index and display the error, or valid value, as appropriate.

updated gist (tested)