dongtan4046 2013-10-16 09:07
浏览 15
已采纳

蛋糕PHP隐藏/显示基于下拉选择的表单元素

How can I show and hide form elements in CakePHP based on a dropdown selection:

Outside of CakePHP, I would usually use jquery or ajax but I cant seem to find anything that tells you how to do this with this scenario in CakePHP.

Here is what I have in the view:

<?php echo $this->Form->create('Spec'); ?>
<fieldset>
    <legend><?php echo __('Add Spec'); ?></legend>
<?php
    echo $this->Form->input('ref');
    echo $this->Form->input('service_id',array('empty'=>'Please Select'));

    echo $this->Form->input('a1',array(
                                                        'label' => 'Background:',
                                                        'div' => false
                                                    ));
    echo $this->Form->input('a2',array(
                                                        'label' => 'Business objectives:',
                                                        'div' => false
                                                    ));

When I select a 'service', dependent on my selection I need to either show or hide a1 and a2.

  • 写回答

1条回答 默认 最新

  • douchensou6969 2013-10-17 11:51
    关注

    This has nothing to do with CakePHP, and Cake is not preventing you from doing this as you normally would. All you're doing with Cake here is using the HTML helpers to output the HTML for your form using PHP.

    Once the page has loaded, your form is there with all the HTML generated, so you are in exactly the same situation as you would be having built any other non-Cake webpage using HTML. You can use jQuery combined with CSS as normal to hide/show the select boxes as the user interacts with them.

    Load jQuery in your Layout file, and add your individual script for this page at the bottom of the view, or also in your Layout file if you like. Really, CakePHP is just the framework to make generating your page easier, but it's all server-side code, so once the user has requested the page and it is loaded by the client, CakePHP has done its job and effectively plays no further part in what you do with your page with regard to client-side interactivity.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集