dongzhang6677 2014-05-30 05:45
浏览 41
已采纳

我如何从CodeIgniter中的选择选项获取文本而不是值

I have a form in which there is a select field with many options. These options have numeric values and a text between option tags. What I want to do is to get the text instead of values when I post the form via submit button.

View that generates the select field:

echo form_dropdown('pos', $pos_options, '100', 'id="pos_select" class="form_input"'); 

the select part generated:

<select name="pos" id="pos_select" class="form_input">
    <option value="0">about_history_title</option>
    <option vlaue="1">about_history</option>
</select>

When the form is submited, the appropriate model is called via the controller(text.php):

text.php -> insert_text()

$this->admin_text_model->insert_text();

admin_text_model.php

public function insert_text()
{
    $data = array(
        'tx_page' => $this->input->post('page'),
        'tx_pos' => $this->input->post('pos'),
        'tx_body' => $this->input->post('add_text')
    );

    return $this->db->insert('text', $data);
}

Is there a way that I can get the text inside option tags in $this->input->post('pos')?

Perhaps something like:

'tx_pos' => $this->input->post('pos')->text?
  • 写回答

3条回答 默认 最新

  • doupo2157 2014-05-30 06:02
    关注

    Try this don't assign the value to option tag:

    <select name="pos" id="pos_select" class="form_input">
        <option>about_history_title</option>
        <option>about_history</option>
    </select>
    

    It will return text of option.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!