こんにちは。ユーザーがユーザーを作成した人と同じaccount_idを持つ新しいユーザーを作成できるフォームを作成しようとしています。
現在、私のページはフォームに正しいaccount_idを表示していますが、フォームをデータベースに送信すると、間違ったものとして保存されます。
これが私の機能です
function add_Employee(){
$accounts=$this->User->find('list', array(
'fields'=>array('account_id'),
'conditions' => array(
'User.id' => $this->Auth->user('id'))));
if($this->request->is('post')){
$this->User->create();
if ($this->User->save($this->request->data))
{
$this->Session->setFlash('The user has been saved');
$this->redirect( array('controller'=>'Users','action' => 'index_admin'));
}
else { $this->Session->setFlash('The user could not be saved. Please, try again.'); }
}
$this->set('accounts',$accounts);
}
とビュー
<h2>Add Employee</h2>
<p>Add a new Employee here, please enter their details below.</p>
<?php
echo $this->Form->create('User', array('action'=>'add_Employee'));
echo $this->Form->input('username',array('label'=>'Username: '));
echo $this->Form->input('password',array('label'=>'Password: '), array('type'=>'password'));
echo $this->Form->input('password_confirmation',array('label'=>'Confirm: '), array('type'=>'password'));
echo $this->Form->input('email',array('label'=>'Email: '));
echo $this->Form->input('title',array('label'=>'Title: '));
echo $this->Form->input('firstname',array('label'=>'First Name: '));
echo $this->Form->input('surname',array('label'=>'Surname: '));
echo $this->Form->input('active', array('default'=>true, 'type'=>'hidden'));
echo $this->Form->input('account_id', array('value'=>$accounts['User']['account_id']));
echo $this->Form->input('access_level', array(
'label' => 'Access Level:',
'options' => array('1'=>'Employee','2'=>'Adminstrator')));
echo $this->Form->end('Submit');
?>