Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Form Questions /

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

Custom Form Template problem

Go to End



Community Member, 1 Post

15 October 2009 at 4:11am

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 %>