Jump to:

2002 Posts in 1422 Topics by 616 members

Form Questions

SilverStripe Forums » Form Questions » Custom Form Validation Error in SESSION

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1205 Views
  • ivo
    Avatar
    Community Member
    19 Posts

    Custom Form Validation Error in SESSION Link to this post

    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?

  • Devlin
    Avatar
    Community Member
    215 Posts

    Re: Custom Form Validation Error in SESSION Link to this post

    Semantics.
    FormName.formError is the message of the form and FormName.errors[] are the messages of the fields.

  • ivo
    Avatar
    Community Member
    19 Posts

    Re: Custom Form Validation Error in SESSION Link to this post

    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?

  • Silverfish
    Avatar
    Community Member
    59 Posts

    Re: Custom Form Validation Error in SESSION Link to this post

    Hi,

    if I get you right you are looking for this:
    http://www.silverstripe.org/form-questions/show/19073#post311384#post311384

    Regards
    SF

  • ivo
    Avatar
    Community Member
    19 Posts

    Re: Custom Form Validation Error in SESSION Link to this post

    ok
    i rendered the errors manually from FormName.errors[]
    that works fine

    thanks both

    1205 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.