如何使两个表单输入都与cakephp相关

如何使两个表单输入都与cakephp相关,cakephp,cakephp-2.0,Cakephp,Cakephp 2.0,我想在我的add.ctp中做这个。 当用户选择部门时,在“文件表单”字段中,仅显示与他们选择的部门相同的文件 在我的add.ctp中 <div class="form-group"> <?php echo $this->Form->input('department', array('class' => 'form-control', 'placeholder' => 'Department', '

我想在我的add.ctp中做这个。 当用户选择部门时,在“文件表单”字段中,仅显示与他们选择的部门相同的文件

在我的add.ctp中

            <div class="form-group">
                <?php echo $this->Form->input('department', array('class' => 'form-control', 'placeholder' => 'Department', 'options' => array( 
                    'Administrator' => 'Administrator',
                    'Multimedia' => 'Multimedia', 
                    'Treasurer' => 'Treasurer',
                    'Marketing' => 'Marketing',
                ), 
                    'empty' => '(Choose Department)',));?>
            </div>
            <div class="form-group">
                <?php echo $this->Form->input('fail_id', array('class' => 'form-control', 'label' => 'File','placeholder' => 'File Id', 'empty' => '(Choose File)'));?>
            </div>

感谢您的帮助。

您必须使用ajax post。用户选择部门后,应发送一篇带有部门值的ajax帖子,获取相关文件并更新第二个组合框。

您必须使用ajax帖子。用户选择部门后,应发送一篇带有部门值的ajax帖子,获取相关文件并更新第二个组合框。

感谢您的好意回复,但我是cakephp新手。你能帮助我如何实现ajax帖子吗。我看不懂网上的任何教程。谢谢你的好意,但我是cakephp新手。你能帮助我如何实现ajax帖子吗。我看不懂网上的任何教程。
public function add() {
    if ($this->request->is('post')) {
        $this->Borrow->create();
            $this->request->data['Borrow']['user_id']= $this->Auth->user('id');
        if ($this->Borrow->save($this->request->data)) {
            $this->Session->setFlash(__('The borrow has been saved.'), 'default', array('class' => 'alert alert-success'));
            return $this->redirect(array('action' => 'index'));
        } else {
            $this->Session->setFlash(__('The borrow could not be saved. Please, try again.'), 'default', array('class' => 'alert alert-danger'));
        }
    }
    $users = $this->Borrow->User->find('list');
    $fails = $this->Borrow->Fail->find('list');
    $fails = $this->Borrow->Fail->find('list');
    $this->set(compact('users', 'fails', 'fails'));
}