Ok here is the dilema. I need to create 2 user forms basically the
same, but they have different validations. The forms are identical
only differance is the validation on the contractor checks the email
field for free email accounts which are not allowed so i split the
forms up into separate controllers to have different validation and
keep the "register" as i do not want to use 2 different action names.
Picky picky....
Here is what I have been trying to do.
employer_controller -> function register(); allows new users to sign
up as a employer, creates the user into the User db no problem
contractor_controller -> function register(); allows new users to sign
up as a contractor, creates the user into the User db no problem
but the employer and contractor "id" is not being created at the same
time...
controller code:
function register()
{
if (!empty($this->data)) {
if (isset($this->data['User']['password2']))
$this->data['User']['password2hashed'] = $this->Auth-
>password($this->data['User']['password2']);
$this->User->create();
$this->data['User']['username'] = $this->data['Employer']
['username'];
$this->data['User']['password'] = $this->Auth->password
($this->data['User']['password2']);
$this->data['User']['group_id'] = '4';
if ($this->User->save($this->data)) {
$userId = $this->User->getLastInsertId();
$this->data['Employer']['user_id'] = $userId;
$this->data['Employer']['group_id'] = '4';
$this->Employer->save($this->data);
$this->Session->setFlash('NEW Employer!');
$this->redirect(array('controller' => 'users',
'action' => 'index'));
} else {
$this->Session->setFlash('Employer error signing up.
Please, try again.');
$this->data = null;
}
}
}
form code:
<h2>Sign up as an Employer</h2>
<div class="employer form">
<?php echo $form->create('Employer', array('action' => 'register'));?>
<fieldset>
<?php
echo $form->input('username', array('label'=>'Username:'));
echo $form->input('password', array('label'=>'Password:'));
echo $form->input('password2', array('label'=>'Confirm
Password:'));
echo $form->input('email', array('label'=>'Email:'));
?>
</fieldset>
<?php echo $form->end('Submit');?>
</div>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---