-
-
Save mooror/cf29e3a8a43b523d9923 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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