Page 1 of 1

Form errror handling strategy

Posted: Sun Sep 04, 2011 12:30 am
by eazyGen
Hi guys,

What techniques do you use to process, validate, and then show errors on your forms.

Do you set an "action" to the same form and then handle errors somewhere?
Do you use a separate script to process validation?
What standards do you apply for the position of the error messages?
Do you alter the "look" of any fields in errors (make them red for example)?

Do you have a good standard strategy that can be applied for all forms in a re-usable fashion? Perhaps using functions?

I am looking for a robust, user friendly (and coder friendly come to that) solution to this frequently encountered situation.

Many thanks for any help.

S

Re: Form errror handling strategy

Posted: Sun Sep 04, 2011 1:19 am
by flying_circus
eazyGen wrote:Hi guys,

What techniques do you use to process, validate, and then show errors on your forms.

Do you set an "action" to the same form and then handle errors somewhere?
Do you use a separate script to process validation?
What standards do you apply for the position of the error messages?
Do you alter the "look" of any fields in errors (make them red for example)?

Do you have a good standard strategy that can be applied for all forms in a re-usable fashion? Perhaps using functions?

I am looking for a robust, user friendly (and coder friendly come to that) solution to this frequently encountered situation.

Many thanks for any help.

S
Setting form actions is one of those things where everyone has their own style. My approach has been to never set navigation in the form through either a get or hidden post variable.

For example, a contact form, lets call it contact.php. When you go to www.example.com/contact.php it will draw a simple form that asks for the basics of an email... to, from, subject, body, etc. I then post the form back to contact.php, which determines wether it is a get or post request, thats how the script knows to validate and process the form or not. This makes it very easy to redraw the form if any of the data does not validate and re-populate form fields should validation error.

As far as how and where to display errors, there is no standard. This is more a topic of UI design as it should mesh well with the look and feel of your website.

I dont have a standard library that makes life easy, but I have made template files. I use includes to include the form template into the view, and then I just have to write the controller side, I typically copy paste from another similar form and modify it to accept the correct form field names.

Re: Form errror handling strategy

Posted: Sun Sep 04, 2011 1:45 am
by eazyGen
flying_circus wrote:
eazyGen wrote:Hi guys,

What techniques do you use to process, validate, and then show errors on your forms.

Do you set an "action" to the same form and then handle errors somewhere?
Do you use a separate script to process validation?
What standards do you apply for the position of the error messages?
Do you alter the "look" of any fields in errors (make them red for example)?

Do you have a good standard strategy that can be applied for all forms in a re-usable fashion? Perhaps using functions?

I am looking for a robust, user friendly (and coder friendly come to that) solution to this frequently encountered situation.

Many thanks for any help.

S
Setting form actions is one of those things where everyone has their own style. My approach has been to never set navigation in the form through either a get or hidden post variable.

Sounds good.

For example, a contact form, lets call it contact.php. When you go to http://www.example.com/contact.php it will draw a simple form that asks for the basics of an email... to, from, subject, body, etc. I then post the form back to contact.php, which determines wether it is a get or post request, thats how the script knows to validate and process the form or not. This makes it very easy to redraw the form if any of the data does not validate and re-populate form fields should validation error.

Keeps things nicely together it would seem. When you mention "POST" and "GET", under what circumstances would you use "GET"? Plus, as a matter of semantics, how do you test if a post or get has occurred?

As far as how and where to display errors, there is no standard. This is more a topic of UI design as it should mesh well with the look and feel of your website.

Yes, I have noticed this. I have often been left to looking a form up and down for some time before I understand the precise nature of my error. A small problem methinks.

I dont have a standard library that makes life easy, but I have made template files. I use includes to include the form template into the view, and then I just have to write the controller side, I typically copy paste from another similar form and modify it to accept the correct form field names.

I started with an MVC structure, but I found myself trying to accommodate both the learning of it and also of the various languages at the same time and not making as much progress as I would have liked. I have discarded MVC for now while I focus on the languages. I can then re-factor things as necessary when more learning has been bedded in.
Many thanks to you for your help.

S