簡體   English   中英

PHP Multiselect與選擇的jQuery-返回所有值,不僅是選定的

[英]PHP Multiselect with Chosen jQuery - Returning all values not just selected

我正在使用多選獲取一些值。 此多選使用選擇的jQuery插件。

由於PHP中的某些原因,此multiselect返回所有值,而不僅僅是返回選定的值。

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>

后阿賈克斯人口

<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] =>學生的反思社區-合作交流思想和過程的自覺環境[1] =>教師包容性對話-強調與學生分享權力;能見度高[2] =>教師反饋-意識到書面,口頭和象征性反饋對學生自我能力的影響[3​​] =>學生自我評估(元認知反射)-學生不斷瘦下來的機會)

即使在多選框中僅選擇了其中一個選項,也會發生這種情況

希望有人能夠對此提供幫助,這是我的職責所在。

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[]' ,因為您希望它們在其中攜帶該值,並且您不想讓您選擇的name成為taglist[]

如果使用列表, taglist[]將選擇名稱保留為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";
    }
}
?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM