I've a page which has two forms on it, one for register and one for
login, cake shows errors on both forms when, for example, the user
leaves the password field blank on the registration form errors will
appear for the password field on both the register form and the login
form because they both have fields called password. To negate this I
found this tutorial http://bakery.cakephp.org/articles/RabidFire/2010/06/26/multiple-forms-per-page-for-the-same-model
which suggests using a different model for each form. So I use RegUser
instead of User and create a model called RegUser in app/models/forms
and the same for LoginUser.
However now my confirm passwords fields won't agree that they match
even when they definately do. I guess this is something to do with the
auth component hashing things but I'm not sure where I'm going wrong.
my view:
<div id="signLeft">
<div class="signFormWrapper">
<h1>New User?</h1>
<?php echo $this->Form->create('RegUser',
array('url'=>array('controller'=>'users', 'action'=>'add')));?>
<fieldset><legend><?php __('Sign Up...'); ?></legend>
<?php echo $this->Form->input('first_name');?>
<?php echo $this->Form->input('last_name');?>
<?php echo $this->Form->input('email');?>
<?php echo $this->Form->input('password');?>
<?php echo $this->Form->input('password2', array('label' =>
'confirm password', 'type' => 'password'));?>
<?php echo $this->Form->end(__('Sign up', true));?
>
</fieldset>
</div>
</div>
<div id="signRight">
<div class="signFormWrapper">
<h1>Returning user?</h1>
<?php echo $this->Form->create('LoginUser', array('url' =>
array('controller' => 'users', 'action' =>'login')));?>
<fieldset><legend>Log in...</legend>
<?php echo $this->Form->input('User.email');?>
<?php echo $this->Form->input('User.password');?>
<?php echo $this->Form->end('Login');?>
</fieldset>
</div>
</div>
My Controller
function add() {
if (!empty($this->data)) {
$this->loadModel('RegUser');
if(isset($this->data['RegUser']['password2'])) {
$this->data['RegUser']['password2hashed'] = $this->Auth-
>password($this->data['RegUser']['password2']);
}
$this->RegUser->create();
if ($this->RegUser->save($this->data)) {
$this->Session->setFlash(__('The user has been saved', true));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The user could not be saved. Please,
try again.', true));
//$this->redirect(array('controller'=>'pages', 'action' =>
'signup'));
$this->render('/pages/signup');
}
}
}
App Controller
class AppController extends Controller {
var $components = array('Auth', 'Session');
var $helpers = array('Html', 'Form', 'Session');
function beforeFilter() {
$this->Auth->authorize = 'controller';
$this->Auth->allow('display');
$this->Auth->fields =
array('username'=>'email','password'=>'password');
}
public function isAuthorized() {
return true;
}
}
--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
No comments:
Post a Comment