Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class ContactPage extends ContactFormPage {
- static $singular_name = 'Contact Page';
- static $plural_name = 'Contacts Pages';
- static $description = 'Contact Page is used for simple content, form and Google Maps integration.';
- static $icon = '';
- private static $db = array(
- 'GoogleAPIKey' => 'Text',
- 'Column1' => 'HTMLText',
- 'Column2' => 'HTMLText',
- 'FormColumn' => 'HTMLText',
- 'Mailto' => 'Varchar(100)',
- 'SuccessMsg' => 'HTMLText',
- 'MapCenteringPoint' => 'Varchar(255)',
- 'Zoomlevel' => 'Varchar(2)'
- );
- private static $has_many = array(
- 'Addresses' => 'AddressData'
- );
- function getCMSFields() {
- // Create Tabs
- $fields = parent::getCMSFields();
- // Additional tools to GridField
- $gridFieldConfig = GridFieldConfig_RecordEditor::create()->addComponents(
- new GridFieldToggleBoolean('Published'),
- new GridFieldAddExistingSearchButton(),
- new GridFieldOrderableRows('SortOrder')
- );
- // Checking for additional Paginator with Show All module
- if(class_exists('GridFieldPaginatorWithShowAll')){
- $paginatorComponent = new GridFieldPaginatorWithShowAll(30);
- $gridFieldConfig->removeComponentsByType('GridFieldPaginator');
- }else{
- $gridFieldConfig->getComponentByType('GridFieldPaginator')->setItemsPerPage(50);
- }
- // Setup GridField Column
- $gridField = new GridField('Addresses', _t('Content.ADDRESSDATA', 'Addresses:'), $this->Addresses(), $gridFieldConfig);
- $t = $fields->findOrMakeTab('Root.GoogleMaps', _t('Content.TABGOOGLEMAPS','GoogleMaps'));
- $t->push($gridField);
- $fields->removeFieldFromTab('Root.Main', 'Content');
- $fields->findOrMakeTab('Root.Column1', _t('Content.TABCOLUMN1','Column 1'));
- $fields->addFieldsToTab('Root.Column1', array(
- new HtmlEditorField('Column1', _t('Content.COLUMN1','Column 1'))
- ));
- $fields->findOrMakeTab('Root.Column2', _t('Content.TABCOLUMN2','Column 2'));
- $fields->addFieldsToTab('Root.Column2', array(
- new HtmlEditorField('Column2', _t('Content.COLUMN1','Column 2'))
- ));
- $fields->findOrMakeTab('Root.GoogleMaps', _t('Content.TABGOOGLEMAPS','GoogleMaps'));
- $fields->addFieldsToTab('Root.GoogleMaps', array(
- new TextField("GoogleAPIKey", _t('Content.GOOGLEAPIKEY','Google API-key')),
- new TextField("MapCenteringPoint", _t('Content.MAPCENTERINGPOINT','Map centering point')),
- new TextField("Zoomlevel", _t('Content.ZOOMLEVEL','Zoom level (def. 14)'))
- ));
- $fields->findOrMakeTab('Root.Form', _t('Content.TABFORM','Form'));
- $fields->addFieldsToTab('Root.Form', array(
- new HtmlEditorField('FormColumn', _t('Content.FORMCOLUMN','Text before Form')),
- new EmailField("Mailto", _t('Content.MAILTO','Receivers E-mail')),
- new HtmlEditorField("SuccessMsg", _t('Content.SUCCESSMSG','Success message to be displayed after form is sent'))
- ));
- return $fields;
- }
- // For LayoutHolder
- function RenderAsChild() {
- $class = $this->ClassName . "_Controller";
- $controller = new $class($this);
- return $controller->renderForHolderPage();
- }
- // holder end
- }
- class ContactPage_Controller extends ContactFormPage_Controller {
- // For LauputHolder
- private static $LayoutTemplate = 'ContactPage';
- function renderForHolderPage() {
- $template = $this->stat('LayoutTemplate');
- if ($template) return $this->renderWith(array($template));
- else return '';
- }
- // holder end
- public function ContactForm() {
- return ContactForm::create("ContactForm","you@example.com","You've received a new contact form!")
- ->addFields(
- TextField::create("Name","What is your name?")
- ->addExtraClass("col-md-6"),
- EmailField::create("Email", "What is your email?")
- ->addExtraClass("col-md-6")
- )
- // You can add fields as strings, too.
- ->addField("Your message//Textarea")
- ->setSuccessMessage("Thanks for submitting the form!")
- ->setSuccessURL($this->Link('success'))
- ->setOnBeforeSend(function($data, $form) {
- // Do stuff here. Return false to refuse the form.
- })
- ->setEmailTemplate("MyCustomTemplate")
- ->addOmittedField("SomeField")
- ->setIntroText("Someone submitted a form. Here's the data.")
- ->addSpamProtector(
- SimpleQuestionSpamProtector::create()
- ->addQuestion("What's the opposite of skinny?","fat")
- ->addQuestion("Which is bigger, a lake or an ocean?","ocean")
- )
- ->render()
- ->setLayout("horizontal");
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement