Skip to content

Instantly share code, notes, and snippets.

@mooror
Created March 10, 2016 02:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mooror/cf29e3a8a43b523d9923 to your computer and use it in GitHub Desktop.
Save mooror/cf29e3a8a43b523d9923 to your computer and use it in GitHub Desktop.
<!-- My form field template (for CheckboxSetField) -->
<!-- Changed the li tags to div tags for testing -->
<ul $AttributesHTML>
<% if $Options.Count %>
<% loop $Options %>
<div class="$Class">
<input id="$ID" class="checkbox-input" name="$Name" type="checkbox" value="$Value"<% if $isChecked %> checked="checked"<% end_if %><% if $isDisabled %> disabled="disabled"<% end_if %> />
<label for="$ID">$Title</label>
</div>
<% end_loop %>
<% else %>
<li>No options available</li>
<% end_if %>
</ul>
<!-- Original form field template (for CheckboxSetField) -->
<ul $AttributesHTML>
<% if $Options.Count %>
<% loop $Options %>
<li class="$Class">
<input id="$ID" class="checkbox" name="$Name" type="checkbox" value="$Value"<% if $isChecked %> checked="checked"<% end_if %><% if $isDisabled %> disabled="disabled"<% end_if %> />
<label for="$ID">$Title</label>
</li>
<% end_loop %>
<% else %>
<li>No options available</li>
<% end_if %>
</ul>
class Page_Controller extends ContentController {
public function NewsletterForm() {
$checkboxArray = $this->RetrieveMailingLists();
$form = Form::create(
$this,
__FUNCTION__,
FieldList::create(
HeaderField::create('HeaderTitle','Select which mail listings you would like sent to this email',4),
EmailField::create('Email','Email(Required)')
->setAttribute('placeholder','e.g. JohnDoe@provider.com')
->addExtraClass('form-control'),
TextField::create('FirstName','First Name (Optional)')
->setAttribute('placeholder','e.g. John')
->addExtraClass('form-control'),
TextField::create('Surname','Last Name (Optional)')
->setAttribute('placeholder','e.g. Doe')
->addExtraClass('form-control'),
CheckboxSetField::create(
'MailingListsSelection',
'I would like to recieve the following mailing lists',
$checkboxArray)
->addExtraClass('checkbox')
->setTemplate('BootstrapCheckboxSetField')
),
FieldList::create(
FormAction::create('handleNewsletterSubscription','Subscribe')
->setUseButtonTag(true)
->addExtraClass('btn btn-success')
),
RequiredFields::create('Email','MailingLists')
);
$form->addExtraClass('form-style')
->setAttribute('name','NewsletterForm')
->customise(array(
'ErrorResponse' => $this->ErrorResponse(),
'SuccessResponse' => $this->SuccessResponse()
));
return $form;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment