【问题标题】:how can i make two form input are related cakephp我怎样才能使两个表单输入相关 cakephp
【发布时间】:2016-05-15 06:05:04
【问题描述】:

我想在我的 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>

在我的控制器中

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'));
}

感谢您的好意帮助。

【问题讨论】:

    标签: cakephp cakephp-2.0


    【解决方案1】:

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

    【讨论】:

    • 感谢您的好意回应,但我是 cakephp 的新手。你能帮我如何实现ajax帖子吗?我无法理解网络上的任何教程。
    猜你喜欢
    • 1970-01-01
    • 2022-11-01
    • 2015-02-07
    • 2021-09-24
    • 1970-01-01
    • 2015-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多