-2

我有一个包含必填字段的表单,一个字段是一个复选框。将显示所有验证错误,但复选框字段没有错误。我安装了 DebugKit-Plugin 并看到,会有一个验证错误,但消息不会显示。

class Users extends AppModel {

public $name = 'Users';
public $validate = array(
    'email' => array(
        'notEmpty' => array(
            'rule' => 'notEmpty',
            'message' => 'Bitte geben Sie ihre Email-Adresse ein',
            'allowEmpty' => false,
        ),
        'isUnique' => array(
            'rule' => 'isUnique',
            'message' => 'Diese Adresse ist bereits angemeldet',
        ),
        'email' => array(
            'rule' => array('email',true),
            'message' => 'Bitte geben Sie eine gültige Email-Adresse ein',
            'allowEmpty' => false,
        ),
    ),
    'terms' => array(
            'rule' => array('comparison','!=',0),
            'message' => 'Sie müssen unseren Nutzungsbedingungen zustimmen',
            'allowEmpty' => false,
    ),
    );    
}

形式:

<div class="right text-right" id="register_form">
    <?php
    echo $this->Form->create('Users', array('action' => 'register', 'inputDefaults' => array()));
    echo $this->Form->input('gender', array('label' => 'Anrede: &nbsp;', 'class' => 'inputField', 'options' => array('m' => 'Herr', 'f' => 'Frau')));
    echo $this->Form->input('first_name', array('label' => 'Vorname: ', 'class' => 'inputField'));
    echo $this->Form->input('last_name', array('label' => 'Nachname: ', 'class' => 'inputField'));
    echo $this->Form->input('email', array('label' => 'Email: ', 'class' => 'inputField'));
    echo $this->Form->input('terms', array('div' => true, 'type' => 'checkbox', 'value' => 0, 'label' => false, 'before' => ' <label for="UsersTerms">Ich akzeptiere die '.$this->Html->link('AGB', array('controller' => 'pages', 'action' => 'terms')).' </label>'));
    echo $this->Form->submit('Anmelden', array('class' => 'button'));
    echo $this->Form->end();
    ?>
</div>

控制器:

public function register() {
    if ($this->Auth->user())
        $this->redirect($this->referer('/'));
    if ($this->request->is("post")) {
        $this->Users->create();
        $this->Users->set(Sanitize::clean($this->request->data));
        #if ($this->Users->validates())
        #    die(debug($this->Users->validationErrors));
        $this->_hash = $this->Auth->password($this->Users->data['Users']['email']);
        $this->_password = $this->__randomString(8, 8);
        $this->Users->set('password', $this->Auth->password($this->_password));
        if ($this->Users->save()) {
            $this->Users->id = $this->Users->getLastInsertID();
            $this->_sendActivationMail();
            $this->Session->setFlash('An die angegebene Emailadresse wurde soeben ein Aktivierungslink versendet.', 'default', array('class' => 'yellow'));
            $this->redirect($this->referer());
        } else {
            $this->Session->setFlash('Ein Fehler ist aufgetreten', 'default', array('class' => 'red'));
        }
    }
}

我尝试使用“$this->Form->error('terms');” 但是当我调试这条线时,如果出现错误,只会有

<div class="error_message"></div>

CakePHP 是最后一个版本。从 4 小时开始搜索寻求帮助,但谷歌没有答案。你?

问候 M。

4

1 回答 1

-1

如果有人有同样的问题,我可以解决我的问题:

问题是特殊字符“ü”。我试图用 ISO 8859-1 保存我的文件,但它需要用 UTF8 保存。现在将显示错误消息。

于 2013-01-31T06:53:55.350 回答