PHP Classes

Error Mesage per field

Recommend this page to a friend!

      PHP Forms Class with HTML Generator and JavaScript Validation  >  PHP Forms Class with HTML Generator and JavaScript Validation package blog  >  Upcoming Visual HTML ...  >  All threads  >  Error Mesage per field  >  (Un) Subscribe thread alerts  
Subject:Error Mesage per field
Summary:.. instead of in a block for the whole form.
Messages:4
Author:Ludwig Ruderstaller
Date:2008-03-06 17:55:02
Update:2008-03-10 14:52:34
 

  1. Error Mesage per field   Reply   Report abuse  
Picture of Ludwig Ruderstaller Ludwig Ruderstaller - 2008-03-06 17:55:02
Hi,

I'm looking for a way to display errormessages with the field in which the error is happend.

When i call:
$this->Validate($verify);

i get the $verify var filled with the fieldnames in which a error happend.
but i didnt find a way to match this with the errormessage itself.

any idea ?

btw. is $server_validate what i asked for in http://www.phpclasses.org/discuss/package/1/thread/111/

thanks
Ludwig

  2. Re: Error Mesage per field   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2008-03-06 23:08:06 - In reply to message 1 from Ludwig Ruderstaller
If you set the forms class variable ShowAllErrors to 1, the Validate() function returns a string with all the errors of all invalid fields.

You can also use the forms class variable Invalid to check what error is set to what field.

The $server_validate is a private variable that the class uses to determine if any field needs server validation. So it is not what you want. I did not had time to had the option you want. Maybe I add it soon.

  3. Re: Error Mesage per field   Reply   Report abuse  
Picture of Ludwig Ruderstaller Ludwig Ruderstaller - 2008-03-10 14:13:49 - In reply to message 2 from Manuel Lemos
Hi,

> "ValidateOnlyOnServerSide"

Its not a problem at the moment, i extend your class and have overwritten you AddInput function which adds the "ValidateOnlyOnServerSide" followed bei parent::AddInput.

> ShowAllErrors=1
Yes, i already did this. Unfortunatly its only a string. For the "Empty" Validation message, its no big problem to parse the right line depending on the label name. For other Errormessages it could be harder.

The only option i see for the moment is to overwrite the Validate function and write $input_error to an array. eg.
$input_errors[$field]=$input_error;

Maybe you want to add an FormClass Var. eg. ErrorsAsArray which defaults to false to keep backward compatibility. so you could at the end of Validate() do eg.

[php]
if($this->ErrorsAsArray){
return $input_errors;
}else{
if($this->ShowAllErrors){
$error=implode($input_errors,$suffix);
}else{
$error=$suffix.end($input_errors).$prefix;
}
return $error;
}
[/php]

what you think ?

Rufinus aka Ludwig

  4. Re: Error Mesage per field   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2008-03-10 14:52:35 - In reply to message 3 from Ludwig Ruderstaller
As I mentioned, you can access the forms class Invalid variable to get the error messages for each field.