Jump to:

1970 Posts in 1272 Topics by 607 members

Form Questions

SilverStripe Forums » Form Questions » Custom form template, error message for server side validation

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

Page: 1
Go to End
Author Topic: 3632 Views
  • Ben_W
    Avatar
    Community Member
    79 Posts

    Custom form template, error message for server side validation Link to this post

    I have read the following doc http://doc.silverstripe.com/doku.php?id=Form. It works 99% percent the way I wanted. What I would like to know is that, is there more documentation on how to customize the form template. You see, in the example given from above link, only contain two 'text' input filed, what happen if I need dropdown, radio, textarea etc, I would think it needs something like, $dataFieldByName('dropDownName'). I will try them out, but more documentation would be very helpful here.

    Second, even though I manage to get this simple form up and running, one thing I found is that if I turn the javascript off, the server side validation seems work all right by not letting script proceed any further, yet, the error message does not show anywhere on the page, some thing is off.

    Any advice would be appreciated, I am running out of time.

    Thank you.

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: Custom form template, error message for server side validation Link to this post

    To add new form elements you just keep adding them to the fields array:

    function MyCustomForm() {
       $fields = new FieldSet(
          new EmailField("Email"),
          new EncryptedField("Password"),
          new DropdownField("Foo1", "Bar1"),
          new CheckboxField("Foo2", "Bar2"),
       );
       $actions = new FieldSet(new FormAction("login", "Log in"));
       return new Form($this, "MyCustomForm", $fields, $actions);
    }

    This page might be more useful to you: http://doc.silverstripe.com/doku.php?id=recipes:forms

    Most likely, you have not created the form action that handles the form response, or your form action does not return anything to the user via a template.

    In the above example, you need to have a 'login' method in the controller of the page where the form is located. This login method should return a template, or redirect to another page.

    Please supply you code (preferable via http://pastie.org) and I can have a closer look at the issue.

  • Ben_W
    Avatar
    Community Member
    79 Posts

    Re: Custom form template, error message for server side validation Link to this post

    Hi Hamish

    Thank you for your reply. I have posted my code on pastie.org. Here is the link: http://pastie.org/522439

    I am aware of these doc you mentioned. I know how to add different type of input into the form, what I am not certain is how to display them in my custom template. Most important, I can't get server side validation error message to be displayed on my custom template.

    Thanks again!

  • Piklets
    Avatar
    Community Member
    36 Posts

    Re: Custom form template, error message for server side validation Link to this post

    I know it has been a while, but here:
    $dataFieldByName(CreditCardNumber)
          <span class="message $dataFieldByName(CreditCardNumber).MessageType">$dataFieldByName(CreditCardNumber).Message</span>

    3632 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.