php – Silverstripe 3.1自定义表单未执行的操作

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – Silverstripe 3.1自定义表单未执行的操作脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个名为ForgotPasswordPage.PHP自定义页面一个ForgotPasswordPage.ss模板.我还在ForgotPassworDForm.PHP中有一个自定义Form类,它在templates / Includes目录中有相应的自定义Form模板ForgotPasswordForm.ss.
表单操作应该调用doForgotPassword,但是从不调用函数,否则,我将被发送到GOOGLE.COM.
这似乎是如此基本,但我有两个开发人员在看它,我们得到的是以下错误

似乎存在技问题.请单击后退按钮,刷新浏览器,然后重试.

在这做错了什么?

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中的方法)

脚本宝典总结

以上是脚本宝典为你收集整理的php – Silverstripe 3.1自定义表单未执行的操作全部内容,希望文章能够帮你解决php – Silverstripe 3.1自定义表单未执行的操作所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。