dsbo44836129 2015-12-10 14:12
浏览 16

将下拉表单转换为可选按钮

I have the following dropdown form :

<select value="<?php echo $salesman; ?>" class="form-control" name="data[Invoice][salesman]" placeholder="Salesman">
    <option value="Unset" <?= ($invoice['Invoice']['salesman']) == 'Unset' ? 'selected' : '' ?>>Please Choose</option>
    <option value="Person 1" <?= ($invoice['Invoice']['salesman']) == 'Person 1' ? 'selected' : '' ?>>Person 1</option>
    <option value="Person 2" <?= ($invoice['Invoice']['salesman']) == 'Person 2' ? 'selected' : '' ?>>Person 2</option>
    <option value="Person 3" <?= ($invoice['Invoice']['salesman']) == 'Person 3' ? 'selected' : '' ?>>Person 3</option>
    <option value="None" <?= ($invoice['Invoice']['salesman']) == 'None' ? 'selected' : '' ?>>None</option>
</select>   

and the SQL code to parse it(snippet) :

$salesman = mysqli_real_escape_string( $this->_con, trim( $data['data']['Invoice']['salesman'] ) );

How would I convert the dropdown to be instead images as in the image I have uploaded? The end result would allow the user to click on multiple people, and have that information stored, and retrieved properly when viewing the page. The people selected will have their button highlighted as such with a custom image.

Sample Image

  • 写回答

1条回答 默认 最新

  • doufan9377 2015-12-10 22:34
    关注

    In order to allow your form to handle multiple values instead of just a single value for salesman, you would need to pass it an array of values

    (e.g. $invoice['Invoice']['salespeople'] = ['Person 1', 'Person 2'];)

    In this case you could represent the data on your form using checkboxes like this:

    <label>Person 1</label><input type="checkbox" name="salespeople[]" value="Person 1" 
        <?= in_array('Person 1', $invoice['Invoice']['salespeople']) ? 'checked' : '' ?>>
    
    <label>Person 2</label><input type="checkbox" name="salespeople[]" value="Person 2" 
        <?= in_array('Person 2', $invoice['Invoice']['salespeople']) ? 'checked' : '' ?>>
    
    <label>Person 3</label><input type="checkbox" name="salespeople[]" value="Person 3" 
        <?= in_array('Person 3', $invoice['Invoice']['salespeople']) ? 'checked' : '' ?>>
    
    <label>None</label><input type="checkbox" name="salespeople[]" value="None" 
        <?= empty($invoice['Invoice']['salespeople']) ? 'checked' : '' ?>>
    

    Then when you submit your form, the script that handles the submission would get an array of salespeople rather than a single salesman.

    It is possible to style the labels+checkboxes as toggle buttons using CSS; you can google for various examples of this.

    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c