Hi there,
I have a module that makes use of a DataExtention on the model and a Extension on the controller. I am not getting the controller side of things to work properly (the model part of the code works fine) My code looks like this:
SidebarEmail.php
-----------------------------------------------------------
class SidebarEmail extends DataExtension {
static $db = array(
'Enquire'=>'Boolean' // Gives user the option to enable or disable enquiry form in CMS
);
public function getCMSFields() {
$this->extend('updateCMSFields', $fields);
return $fields;
}
public function updateCMSFields(FieldList $fields) {
$enquiredropdown = array('0'=>'No','1'=>'Yes');
$fields->addFieldToTab('Root.Main', new DropDownField('Enquire', 'Enable Enquiry Form?', $enquiredropdown),'Title');
return $fields;
}
}
class SidebarEmail_Controller extends Extension {
public static $allowed_actions = array (
'EnquiryForm'
);
public function init() {parent::init(); }
// ENQUIRY FORM
public function EnquiryForm(){
$fields = new FieldList(
new TextField('Name', 'Your name & surname:'),
new TextField('Tel', 'Your phone number:'),
new EmailField('Email', 'Your email address:'),
new TextAreaField('Comments', 'Your query/comment:'),
new RecaptchaField('MyCaptcha')
);
//Form Action
$actions = new FieldList(
new FormAction('SendContactForm', 'Submit')
);
//Create Validators
$validator = new RequiredFields('Name', 'Email', 'Comments');
//Create form
$form = new Form($this, 'EnquiryForm', $fields, $actions, $validator);
return $form;
}
}
_config.php
----------------------------------------------------------------------------------------
SiteTree::add_extension('SidebarEmail');
SiteTree::add_extension('Page_Controller', 'SidebarEmail_Controller');
----------------------------------------------------------------------------------------