General developer forum

Is this form clean or does it have validation errors?

 
Picture of Martin Greenaway
Is this form clean or does it have validation errors?
 

Hi,

I'm trying to do some form design which auto-fills and hides away sections that the user does not need to fill in if we already have information.  There's nothing more off-putting to a user than having to fill out 20 fields of information when they've already given you 15 of them.

At a certain point, for what I'm trying to achieve, it's become apparent that I need the code to behave differently depending on whether I'm presenting the form to the user in a "clean" state, i.e. for them to add/edit the contents, or whether I'm presenting it back to them because some items have failed validation.

(Basically, I don't want to overwrite user-entered data when the form is reloaded from server side validation failures).

Is there a php function I can call, either in my form class or in the page itself, which will tell me at the point of execution whether the form contains errors?  I know I can *create* an errors array, and that this is automagically turned into error labels when the form is displayed, but is that errors array stored anywhere within the form object when instantiated, for instance?

Many thanks in advance!


 
Average of ratings: -
Picture of Martin Greenaway
Re: Is this form clean or does it have validation errors?
 

I have solved this in Javascript, by grabbing the array of div.error elements, and working out if length is greater than 0. However, if there is a way to do this in PHP it would be massively preferable.

 
Average of ratings: -