使用选择的jQuery进行PHP Multiselect - 返回不仅仅选择的所有值

时间:2013-02-11 23:11:58

标签: php jquery forms multi-select jquery-chosen

我正在使用多选来获取一些值。这个多选使用的是选择的jQuery插件。

由于PHP中的某些原因,这个多选项返回所有值,而不仅仅是选定的值。

HTML

<select name="taglist[]" size="10" id="taglist" style="width:350px;" class="chzn-select" multiple multiple-data-placeholder="Select some tags" >
**This is populated by Ajax**
</select>

Ajax人口后

<option value="Student community of reflection - A conscious environment of cooperative sharing of ideas and proces">Student community of reflection - A conscious environment of cooperative sharing of ideas and proces</option>
<option value="Teacher inclusive conversations - Emphasis on a sharing of power with students; visibility that enco">Teacher inclusive conversations - Emphasis on a sharing of power with students; visibility that enco</option>
<option value="Teacher feedback - Awareness of the power of written, oral and symbolic feedback on students self co">Teacher feedback - Awareness of the power of written, oral and symbolic feedback on students self co</option>
<option value="Student self assessment ( metacognitive reflection) - Continuous opportunities for students to thin">Student self assessment ( metacognitive reflection) - Continuous opportunities for students to thin</option>

PHP

foreach ($_REQUEST['taglist'] as $value)
{
mysql_query("INSERT INTO recent_tags (t_name, t_owner, t_post) VALUES ('$value', '$uid',  '$id')") or die (mysql_error());
}

结果

数组([0] =&gt;学生反思社区 - 一个有意识的合作共享思想和过程的环境[1] =&gt;教师包容性对话 - 强调与学生分享权力; enco的可见性[2] ] =&gt;教师反馈 - 意识到学生自我写作,口头和象征性反馈的能力[3] =&gt;学生自我评估(元认知反思) - 学生持续减少的机会)

即使在多选框中只选择了其中一个选项

,也会发生这种情况

希望有人能够帮助解决这个问题,它正在努力。

print_r的结果($ _ POST)

Array ( [entry_name] => aaa [entry_content] => [tag_category] => Insider Classroom Framework [taglist] => Array ( [0] => Student community of reflection - A conscious environment of cooperative sharing of ideas and proces [1] => Teacher inclusive conversations - Emphasis on a sharing of power with students; visibility that enco [2] => Teacher feedback - Awareness of the power of written, oral and symbolic feedback on students self co [3] => Student self assessment ( metacognitive reflection) - Continuous opportunities for students to thin ) [button] => Post ) 

表格帖子

<form id="form1" name="form1" method="post" onSubmit="return checkAll();" action="process/webpl_journal_entry_process.php">

1 个答案:

答案 0 :(得分:1)

我认为您的HTML已关闭。你有:

<select name="taglist[]" size="10" id="taglist" style="width:350px;" class="chzn-select" multiple multiple-data-placeholder="Select some tags" >
**This is populated by Ajax**
</select>

我无法看到你的'内部复选框'看起来如何,但我几乎可以肯定你没有它们name='taglist[]',你希望它们携带那个价值,以及您不希望自己选择nametaglist[]

如果您使用的是列表,那么您希望将选择名称保留为taglist[],但不想命名任何内部选项,只需拥有value

修改 显示所有代码,并且工作正常:

<form action="" method="post">
<select name="taglist[]" size="10" id="taglist" style="width:350px;" class="chzn-select" multiple multiple-data-placeholder="Select some tags" >
<option value="Student community of reflection - A conscious environment of cooperative sharing of ideas and proces">Student community of reflection - A conscious environment of cooperative sharing of ideas and proces</option>
<option value="Teacher inclusive conversations - Emphasis on a sharing of power with students; visibility that enco">Teacher inclusive conversations - Emphasis on a sharing of power with students; visibility that enco</option>
<option value="Teacher feedback - Awareness of the power of written, oral and symbolic feedback on students self co">Teacher feedback - Awareness of the power of written, oral and symbolic feedback on students self co</option>
<option value="Student self assessment ( metacognitive reflection) - Continuous opportunities for students to thin">Student self assessment ( metacognitive reflection) - Continuous opportunities for students to thin</option>
</select>
<input type="submit">
</form>
<?php
if($_REQUEST['taglist']) {

    foreach ($_REQUEST['taglist'] as $value)
    {
        echo $value ."<br>\n";
    }
}
?>