【问题标题】:Cakephp2 form doesn't function redirect to the confirm pageCakephp2 表单无法重定向到确认页面
【发布时间】:2014-06-11 04:03:38
【问题描述】:

我是这个社区的新手,我想问你关于 cakephp2 的验证和表单的问题。 我有一个名为 input() 的方法,该方法旨在将表单变量发送到确认页面。但问题是,即使我按下他的提交按钮,它也不会进入确认页面。 这是脚本,但我不确定它为什么起作用?如果您能帮助我,那就太好了!

public function input() {
    $this->title = 'contact';

    if ($this->request->is('post')) {
                //die(1);
        $data = arrayWithKeys(
            $this->request->data['Contact'],
            array('name', 'email', 'contact_category', 'message'));
        $this->Contact->set($data);
        $ret = $this->Contact->validates();
                     //die(3);
        if ($ret) {
            $this->Session->write(self::SES_CONTACT_INFO, $data);

            $this->redirect(array('controller' => 'contacts', 'action' => 'confirm'));
        } else {
            $this->Session->setFlash(
                $this->Contact->getValidationErrorsAsHtml(), 'error');
        }
                   // die(4);
    } else {
        $contact = $this->Session->read(self::SES_CONTACT_INFO);
        if ($contact) {
            $this->request->data['Contact'] = $contact;
        }
    }

    $this->set('contact_categories', $this->Contact->ContactCategory->find('list'));
}

【问题讨论】:

    标签: forms validation cakephp-2.0


    【解决方案1】:

    对于身份验证,请按照以下示例设置基础知识。对于重定向使用类似

    $this->redirect(array('action' => 'edit', 5));

    // 1.Basic setup
    $this->Auth->authenticate = array('Form');
    
    // Pass settings in
    $this->Auth->authenticate = array(
        'Basic' => array('userModel' => 'Member'),
        'Form' => array('userModel' => 'Member')
    );
    
    // Pass settings in using 'all'
    $this->Auth->authenticate = array(
        AuthComponent::ALL => array('userModel' => 'Member'),
        'Basic',
        'Form'
    );
    

    【讨论】:

    • 我已经更改了设置,您提供的示例提示了我该怎么做!
    猜你喜欢
    • 2021-07-11
    • 1970-01-01
    • 2018-09-17
    • 2013-08-17
    • 1970-01-01
    • 2013-07-08
    • 1970-01-01
    • 2017-04-30
    • 2021-03-15
    相关资源
    最近更新 更多