Jump to:

1999 Posts in 1408 Topics by 613 members

Form Questions

SilverStripe Forums » Form Questions » Custom Form Template problem

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

Page: 1
Go to End
Author Topic: 1178 Views
  • mr-hood
    Community Member
    1 Post

    Custom Form Template problem Link to this post

    This is probably a general SS problem, but I'm finding this while doing forms I have a working custom form template which works nice. However, all the fields needs to be fitted in three <fieldset>'s instead of the original one.

    I don't figure out how to do that. Using <% if First %>, Last, etc works fine, but not when I need to do this on specific positions.

    I found some tips that the DataObject-view needs to be extended to be able to work around that, but how do I do that? My code looks something like this:

    class MyForm extends Form {
    function forTemplate() {
    return $this->renderWith( array( $this->class, 'Form' ) );

    class CashierPage_Controller extends Page_Controller {
    function form() {
    $fields = new FieldSet(
    new TextField( 'Name', 'Your name' ),
    new TextField( 'Country', 'Country' ),
    new EmailField( 'Phone', 'Phone number' ),
    new TextField( 'Email', 'Email' ),
    new TextField( 'Location', 'Location where ticket was generated' )

    $actions = new FieldSet(
    new ResetFormAction( 'ClearAction', 'Cancel' ),
    new FormAction( 'doFormSubmit', 'Send!' )

    return new MyForm( $this, 'Form', $fields, $actions );

    And template something like this:

    <form $FormAttributes>
    <% 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 %>

    <% control Fields %>
    <% if First %>
    <legend>General information</legend>
    <table border="0" cellpadding="0" cellspacing="0">
    <% end_if %>
    <th><label for="$Id">$Title</label></th>
    <% if Last %>
    <% end_if %>
    <% end_control %>

    <% if Actions %>
    <% control Actions %>$Field<% end_control %>
    <% end_if %>

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.