Password Confirm Validation CakePHP

故事扮演 提交于 2019-12-05 17:20:36

two fields in view file

echo $this->Form->input('password');
echo $this->Form->input('repass');

Model file

<?php
class Post extends AppModel {
    public $validate = array(
        'repass' => array(
            'equaltofield' => array(
            'rule' => array('equaltofield','password'),
            'message' => 'Require the same value to password.',
            //'allowEmpty' => false,
            //'required' => false,
            //'last' => false, // Stop validation after this rule
            'on' => 'create', // Limit validation to 'create' or 'update' operations
            )
        )
    );

function equaltofield($check,$otherfield)
    {
        //get name of field
        $fname = '';
        foreach ($check as $key => $value){
            $fname = $key;
            break;
        }
        return $this->data[$this->name][$otherfield] === $this->data[$this->name][$fname];
    } 
}?>

Seems like your model is not loading correctly and using a dynamically generated model.

Comparing passwords in 2.x is nothing more than comparing any two fields as cake no longer hashes the pw automatically.

Can you confirm your validation method is being run, seems like its not especially if simple things like notEmpty is not working.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!