开发者

CakePHP Validation Question with Plugin

In my CakePHP application, I have setup the PersistantValidation plugin to validate my forms on the model level thanks to a kind previous suggestion. The plugin essentially makes it so that you can use model validation on a partial without having it redirect to the underlying page (ie. the register.ctp view or the login.ctp view, for example).

The validation works great for the login form, but it's not working properly on the user registration form for some reason.

The controller looks like this:

function register开发者_开发技巧() {
  if(!empty($this->data)) {
   $name = $this->data['User']['name'];
   $email = $this->data['User']['email'];
   $password = $this->Password->generatePassword();
   $this->data['User']['password'] = $this->Auth->password($password);
   $this->User->create();
   if($this->User->save($this->data)) {
    $this->Session->setFlash(__('Your account has been created!', true));
    $this->redirect(array('controller' => 'users', 'action' => 'offers'));
   } else {
    $this->redirect($this->referer());
   }
  }
 }

The PresistentValidation component is also properly setup and included, since it works just fine in the login() function in the same controller. When I run this code, nothing happens. There is no redirect away from the partial, which is good, but the errors don't show up. Also, the errors do show up going to the register.ctp view, which means it isn't a problem with the validations themselves.

Does anyone have any ideas?


function register() {
    if(!empty($this->data)) {
        $this->data['User']['password'] = $this->Auth->password($password);
        if($this->User->save($this->data)) {
            $this->Session->setFlash(__('Your account has been created!', true));
            $this->redirect(array('controller' => 'users', 'action' => 'offers'));
        } else {
            $this->redirect($this->referer());
        }
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜