1778 Posts in 581 Topics by 555 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 593 Views |
-
Custom Form Validation Error in SESSION

21 January 2012 at 12:01am Last edited: 21 January 2012 12:06am
Hi,
i have a custom Form:class ContactForm extends Form {...}
which gets passed a Validator
$validator = new RequiredFields('Name', 'Email', 'Comments');
return new ContactForm($this, 'ContactForm', $fields, $actions, $validator);The validator seems to work because in the Session there are Errors:
array
'errors' =>
array
0 =>
array
'fieldName' => string 'Name' (length=4)
'message' => string '"Name*" wird benötigt.' (length=23)
'messageType' => string 'required' (length=8)But in Form.php from sapphire the Message() method looks for 'formError' key and so the validation errors arent found in $Message:
$this->message = Session::get("FormInfo.{$this->FormName()}.formError.message");
How comes that the validation errors of the custom Form are stored in 'errors' instead of 'formError' in the SESSION?
-
Re: Custom Form Validation Error in SESSION

24 January 2012 at 9:24am
Semantics.
FormName.formError is the message of the form and FormName.errors[] are the messages of the fields. -
Re: Custom Form Validation Error in SESSION

26 January 2012 at 5:01am
Alright
I had expected them in FormName.formError, thou.
I thouht the Validator of the form would place them there automatically.So they could be rendered as usual:
<% if Message %>
<p id="{$FormName}_error" class="message $MessageType">$Message</p>
<% else %>
<p id="{$FormName}_error" class="message $MessageType" style="display: none;"></p>
<% end_if %>What do i have to do to get them there?
-
Re: Custom Form Validation Error in SESSION

26 January 2012 at 10:58pm Last edited: 26 January 2012 10:58pm
Hi,
if I get you right you are looking for this:
http://www.silverstripe.org/form-questions/show/19073#post311384#post311384Regards
SF -
Re: Custom Form Validation Error in SESSION

28 January 2012 at 4:14am
ok
i rendered the errors manually from FormName.errors[]
that works finethanks both
| 593 Views | ||
|
Page:
1
|
Go to Top |



