$_POST not receiving form Multi-select
Posted: Wed Sep 09, 2009 7:30 am
I'll make this short and sweet.
I have a form which contains several input fields and a couple of select fields.
The form is defined as:
*Note: the form simply submits to the current page, hence no action redirect.
The select field on the left contains a list of items, the select field on the right is empty and is populated by moving items from the left select field to the right select field through use of a JavaScript.
*Note: the page is compiled using a template class
The PHP page which receives this information is 'initalize.php' through POST.
Upon receiving the POST information from this form, i print the contents of $_POST.
Now the problem is, I am receiving all other input field values minus the the select fields (shopList or products).
Any suggestions why I am not receiving my <select> values in my $_POST?
And how might I be able to remedy this problem?
::Also, if you need the entire code I can post it, its just a tad long so i only included the important parts
cheers
Weiry
I have a form which contains several input fields and a couple of select fields.
The form is defined as:
Code: Select all
<form action="" method="post" id="settings_form">The select field on the left contains a list of items, the select field on the right is empty and is populated by moving items from the left select field to the right select field through use of a JavaScript.
Code: Select all
function addItem() {
var products = document.getElementById('products[]');
var indexes = new Array();
for(var ii=0; ii<products.length; ii++) {
if(products.options[ii].selected) {
var ele = document.createElement("option");
ele.innerHTML = products.options[ii].innerHTML;
ele.value = products.options[ii].value;
document.getElementById('shopList[]').options.add(ele);
indexes.push(ii);
}
}
for(var ii=indexes.length-1;ii>=0;ii--) {
products.options.remove(indexes[ii]);
}
}
function removeItem() {
var shoppingList = document.getElementById('shopList[]');
var indexes = new Array();
for(var ii=0; ii<shoppingList.length; ii++) {
if(shoppingList.options[ii].selected) {
var ele = document.createElement("option");
ele.innerHTML = shoppingList.options[ii].innerHTML;
ele.value = shoppingList.options[ii].value;
document.getElementById('products[]').options.add(ele);
indexes.push(ii);
}
}
for(var ii=indexes.length-1;ii>=0;ii--) {
shoppingList.options.remove(indexes[ii]);
}
}
Code: Select all
Available products<br />
<select multiple="multiple" name="products[]" id="products[]" ondblclick="addItem()" size="10">
${loop:products}<option value="${products.product_id}">${products.product_name}</option>${/loop:products}
</select>
</td>
<td><input type="button" onclick="addItem()" value="->" /><br /><input type="button" onclick="removeItem()" value="<-" /></td>
<td class="tableLeft">
Shopping list<br />
<select multiple="multiple" name="shopList[]" id="shopList[]" ondblclick="removeItem()" size="10">
</select>
The PHP page which receives this information is 'initalize.php' through POST.
Upon receiving the POST information from this form, i print the contents of $_POST.
Code: Select all
5 print_r($_POST);
6 if($_POST['shopList']){foreach($_POST['shopList'] as $t){print $t."<br/>";}}
Code: Select all
Notice: Undefined index: shopList in initialize.php on line 6And how might I be able to remedy this problem?
::Also, if you need the entire code I can post it, its just a tad long so i only included the important parts
cheers
Weiry