PHP Multiselect with Chosen jQuery - 返回所有值而不仅仅是选择的值

标签 php jquery forms multi-select jquery-chosen

我正在使用多重选择来获取一些值。此多选使用 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());
}

结果

Array ( [0] => 学生反射(reflection)社区 - 一个有意识地合作分享想法和过程的环境 [1] => 教师包容性对话 - 强调与学生分享权力;enco [2] = 的可见性> 教师反馈 - 意识到书面、口头和象征性反馈对学生 self 认知的力量 [3] => 学生 self 评估(元认知反射(reflection)) - 为学生提供持续瘦身的机会

即使在多选框中仅选择了其中一个选项,也会发生这种情况

希望有人能够帮助解决这个问题,这让我很头疼。

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">

最佳答案

我认为您的 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[],但不想命名任何内部选项,只需拥有其 的。

编辑: 显示所有代码,并且工作正常:

<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";
    }
}
?>

关于PHP Multiselect with Chosen jQuery - 返回所有值而不仅仅是选择的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14822685/

相关文章:

PHP:选择表单菜单列表错误

javascript - 如果 ng-click 附加到提交按钮,则表单不验证

php - SQLSTATE[HY093] : Invalid parameter number: no parameters were bound, 但提供了参数

php - MySQL数据库xampp

php - 将 Codeigniter 的上传库与 Uploadify 结合使用 (Uploadifive)

javascript - angularjs 从一个巨大的列表中更新单个元素

javascript - 带有切换 div 显示/隐藏的列表

jquery .next() 缺少注入(inject)的表单元素

forms - CakePHP 3 更改单选输入模板

php - 阿拉伯语中的 Sphinx Search 2.2.5 不工作