dongzi3434 2012-12-14 17:22
浏览 34

在Dropdown中创建第一个值(' - select-')为NULL

We have a form with some optional values, which are contained in a dropdown list. When a new user opens the form, the default value on the dropdowns should be '-select-'. The value that the user picks gets sent to our database. This all works fine right now, except we do not have '-select-' listed as the first option, the default is instead the first option as listed in our database.

I am trying to add '-select-' but I receive a database error when I submit the form with '-select-' still chosen.

<div class="control-group">
<label class="control-label">Pricing Profile: </label>
<div class="controls">
    <?php 
    echo form_dropdown('pricing_profile_id', $pricing_profiles, 
              $profile->pricing_profile_id,' class="span3" id="pricing_profile_id" ');
    ?>
</div>
</div>

I tried adding in this text above the "echo form_dropdown" but it does not seem to work:

array_unshift($pricing_profiles, array(0 => "-select-"));

Thanks

  • 写回答

4条回答 默认 最新

  • dongwei4444 2012-12-14 17:23
    关注
    1. Have "select" as one of the chooses in your list
    2. Have the value of select as "" (i.e. no value) for example: ( '' => 'Select' )
    3. Run form validation on the form (which you should be doing anyway). Make the dropdown lists "required"
    4. If the user does not select anything, the form validation fails, since they did not "select" something.
    评论

报告相同问题?

悬赏问题

  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答