嘿伙计们我试图为我的网站创建一个简单的联系表单。我正在使用ShaeDawson的块模块。
我收到以下错误:
"未捕获的异常:对象 - > __ call():方法' contactform'不 在Block_Controller'"
上不存在
以下是我的块的代码:
<?php
class ContactBlock extends Block {
private static $db = array(
'ContainToGrid' => 'Boolean',
'SectionBGColour' => 'Varchar',
'GridBGColour' => 'Varchar',
'OverrideEmail' => 'Varchar'
);
private static $singular_name = 'Contact Form';
private static $plural_name = 'Contact Forms';
public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab("Root.Main", HeaderField::create('BlockSettings', 'Block settings')->setHeadingLevel(2), "ManyMany[BlockArea]");
$fields->addFieldToTab("Root.Main", CheckBoxField::create("ContainToGrid", "Contain in grid?"));
//Background colours of section
$fields->addFieldToTab("Root.Main", TextField::create("SectionBGColour", "Block Background Colour")
->setDescription('(Optional) Leave blank for transparent'));
$fields->addFieldToTab("Root.Main", TextField::create("GridBGColour", "Grid Background Colour")
->setDescription('(Optional) Leave blank for transparent')
->displayIf('ContainToGrid')->isChecked()->end());
$fields->addFieldToTab("Root.Main", HeaderField::create('EmailNotifications', 'Email Notification')->setHeadingLevel(2));
$fields->addFieldToTab("Root.Main", TextField::create("OverrideEmail", "OverrideEmail")
->setDescription('(Optional) Entering an email address here will override the email set in site settings'));
return $fields;
}
public function ContactForm(){
return $this->getController()->ContactForm();
}
}
class ContactForm_Controller extends Block_Controller {
private static $allowed_actions = array(
'ContactForm'
);
public function ContactForm(){
$fields = FieldList::create(array(
TextField::create('Name'),
EmailField::create('Email'),
TextField::create('Organisation'),
TextAreaField::create('Message')
));
$actions = FieldList::create(
FormAction::create('submit', 'Send Enquiry')
);
return Form::create($this, 'ContactForm', $fields, $actions);
}
public function submit($data, $form){
// process form data as usual
// ...
// redirect
return $this->redirect($this->pageLink() . '?contacted=1');
}
}
答案 0 :(得分:0)
解决了这个问题。菜鸟错误。
我需要更改我的&#39; Block Controller&#39;延伸自:
ContactForm_Controller
为:
ContactBlock_Controller
...唉