php – Silverstripe 3.1自定义表单未执行的操作
发布时间:2020-05-25 09:16:42 所属栏目:PHP 来源:互联网
导读:我有一个名为ForgotPasswordPage.php的自定义页面和一个ForgotPasswordPage.ss模板.我还在ForgotPasswordForm.php中有一个自定义Form类,它在templates / Includes目录中有相应的自定义Form模板ForgotPasswordForm.ss. 表单操作应该调用doForgotPassword,但是
|
我有一个名为ForgotPasswordPage.php的自定义页面和一个ForgotPasswordPage.ss模板.我还在ForgotPasswordForm.php中有一个自定义Form类,它在templates / Includes目录中有相应的自定义Form模板ForgotPasswordForm.ss.
似乎存在技术问题.请单击后退按钮,刷新浏览器,然后重试. 我在这做错了什么? ForgotPasswordForm.php <?php
class ForgotPasswordForm extends Form {
function __construct($controller,$name,$arguments=array()) {
$fields = new FieldList(
EmailField::create("Email")
);
$actions = new FieldList(FormAction::create("doForgotPassword")->setTitle("RETRIEVE PASSWORD"));
$validator = new RequiredFields('Email');
parent::__construct($controller,$fields,$actions,$validator);
}
public function doForgotPassword($data,Form $form) {
//As a test,if we ever get here,the controller should send me to the Google website
Controller::curr()->redirect('http://www.google.com');
}
public function forTemplate() {
return $this->renderWith(array(
$this->class,'Form'
));
}
}
ForgotPasswordForm.ss <form $FormAttributes>
<label for="{$FormName}_Email">Enter Your Email Address</label>
$Fields.dataFieldByName(Email)
<% if $Actions %>
<% loop $Actions %>
$Field
<% end_loop %>
<% end_if %>
</form>
ForgotPasswordPage.php class ForgotPasswordPage extends Page {
.
.
.
}
class ForgotPasswordPage_Controller extends Page_Controller {
public static $allowed_actions = array (
'MyForgotPasswordForm'
);
public function init() {
parent::init();
}
public function MyForgotPasswordForm(){
return new ForgotPasswordForm($this,'MyForgotPasswordForm');
}
}
ForgotPasswordPage.ss . . . $MyForgotPasswordForm . . .为了保护表单免受xsrf攻击,silverstripe表单通常使用一个额外的隐藏字段构建,该字段填充有安全令牌,在提交时会对其进行检查.通过重写表单的模板文件,不再包含此标记.您可以通过在ForgotPasswordForm.ss中$Fields.dataFieldByName(Email)之后添加$Fields.dataFieldByName(SecurityID)来包含它.或者,您可以遍历字段,这是一个更强大的解决方案(这是Form.ss中的方法) (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
