douxian9060 2016-09-09 16:36
浏览 8
已采纳

CodeIgniter多选不用单引号选择值

So I'm using the form helper to set up a multiselect like so:

$certifiedTeacher = "I'm storing a value";
echo form_multiselect('certifiedTeacer', $certifiedTeacher, set_value('certifiedTeacher', $certifiedTeacher), 'id="certifiedTeacher" class="multiselect"');

After form post the correct value, in this example "I'm storing a value", is saved in the database. When I reload the page there are no values selected in the field.

If I select a field without a single quote everything works as expected and upno return that value is preselected.

  • 写回答

1条回答 默认 最新

  • duandong1963 2016-09-09 17:26
    关注

    I figured it out on my own. the issue is that the set_value function from CodeIgniter automatically escapes the HTML characters. Since $certifiedTeacher was not encoded they did not match.

    The set_value function offers a third boolean parameter that allows you to turn off HTML escaping. This solved my issue. The new, corrected code is below:

    $certifiedTeacher = "I'm storing a value";
    //false added as a third parameter for set_value to turn off HTML escaping.
    echo form_multiselect('certifiedTeacer', $certifiedTeacher, set_value('certifiedTeacher', $certifiedTeacher, false), 'id="certifiedTeacher" class="multiselect"');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?