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 /

Form with custom template shows wrong validation errors


Go to End
Reply


591 Views

Avatar
boosis

Community Member, 8 Posts

28 May 2011 at 8:32am

I have the following custom form

        $list = DataObject::get('AreaOfExpertise');
        foreach ($list as $l) {
            $source[$l->ID] = $l->Name;
        }
        $fields = new FieldSet(
            new TextField('Customer'),
            new TextField('ProjectName'),
            new DateField('WinDate'),
            new TextareaField('Details'),
            new OptionsetField('AreaOfExpertiseID', 'Area Of Expertise', $source),
            new TextField('ProjectValueLength'),
            new TextField('DeliverTimeframe'),
            new TextField('ProjectTeam'),
            new TextField('Contact')
        );
        $actions = new FieldSet(
            new FormAction('doSubmit', 'Submit')
        );
        $requiredFields = array(
            'Customer',
            'ProjectName',
            'WinDate',
            'Details',
            'AreaOfExpertiseID',
            'ProjectValueLength',
            'DeliverTimeframe',
            'ProjectTeam',
            'Contact',
        );
        $validator = new RequiredFields($requiredFields);
        $form = new Form($this, 'SubmissionForm', $fields, $actions, $validator);
        $form->setTemplate('Forms/NewWinForm');
        return $form;

and my template for this form is

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

    <fieldset id="formContainer" class="clearfix NewWinForm">

            <div id="Customer" class="row field text">
                <label class="left" for="{$FormName}_Customer">Customer</label>
                <div class="middleColumn">$dataFieldByName(Customer)</div>
            </div>
            <div id="ProjectName" class="row field text">
                <label class="left" for="{$FormName}_ProjectName">Project name</label>
                <div class="middleColumn">$dataFieldByName(ProjectName)</div>
            </div>
            <div id="WinDate" class="row field text">
                <label class="left" for="{$FormName}_WinDate">Win date</label>
                <div class="middleColumn">$dataFieldByName(WinDate)</div>
            </div>
            <div id="AreaOfExpertiseID" class="row field text">
                <label class="left" for="{$FormName}_AreaOfExpertiseID">Area of expertise</label>
                <div class="middleColumn">$dataFieldByName(AreaOfExpertiseID)</div>
            </div>

            <div id="Details" class="row field textarea">
                <label class="left" for="{$FormName}_Details">Project details</label>
                <div class="middleColumn">$dataFieldByName(Details)</div>
            </div>
            <div id="ProjectValueLength"  class="row field text">
                <label class="left" for="{$FormName}_ProjectValueLength">Project value/length</label>
                <div class="middleColumn">$dataFieldByName(ProjectValueLength)</div>
            </div>
            <div id="DeliverTimeframe"  class="row field text">
                <label class="left" for="{$FormName}_DeliverTimeframe">Delivery timeframe</label>
                <div class="middleColumn">$dataFieldByName(DeliverTimeframe)</div>
            </div>
            <div id="ProjectTeam"  class="row field text">
                <label class="left" for="{$FormName}_ProjectTeam">Project team</label>
                <div class="middleColumn">$dataFieldByName(ProjectTeam)</div>
            </div>
            <div id="Contact"  class="row field text">
                <label class="left" for="{$FormName}_Contact">Contact</label>
                <div class="middleColumn">$dataFieldByName(Contact)</div>
            </div>
    </fieldset>
    <div class="Actions">
        <% if Actions %>
             <% control Actions %>$Field<% end_control %>
        <% end_if %>
    </div>
</form>        

When I submit the form, instead of "Please fill out "Customer", it is required." message I get "Please fill out "this", it is required."

Can someone please tell me what I am doing wrong? It's killing me...