Hi,
I am hoping that someone can come up with a solution to a problem I am having.
I have a self processing form with two select lists. basically I want the left list populated with some default values and when an item is selected and the submit button pressed the value is copied over to the select box on the right. Values can be added and removed at will.
I have attempted to do this by creating a hidden field with the right hand select box's contents in:
<input type="hidden" name="current_cont[]" value="<?=$cont?>">
when I load the page I check for current_cont. If it is populated I create the new right hand list by merging current_cont and the results from any select operation on the left hand list.
When I try to use this I am getting valid values on the first select, but subsequently all that is displayed is a list containing array and the last value I selected.
I hope that this makes sense and can be followed.
Many thanks
[SOLVED] php self processing forms and passing arrays
Moderator: General Moderators
feyd | Please use
feyd | Please use
Code: Select all
tags when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Sorry was playing with the code.Correct version is as below.
Thanks for any helpCode: Select all
<?php
$add = (isset($_POST['add'])) ? $_POST['add'] : ""; //add tasks button was pressed
$remove = (isset($_POST['remove'])) ? $_POST['remove'] : ""; //remove task button was pressed
$objectslist=("one","two","three","four");
if ($add)
{
$select = (isset($_POST['select'])) ? $_POST['select'] : "";
if(isset($_POST['list_contents']))
{
$included_tasks = array_merge($_POST['list_contents'], $select);
}
else
{
$included_tasks = $select;
}
}
if ($remove)
{
//implement remove code
}
//ouput html header
page_header();
?>
<form action="<?=PHP_SELF?>" method="POST">
<?php if (isset($included_tasks)){?>
<INPUT type="hidden" name="list_contents[]" value="<?=$included_tasks?>">
<?php }?>
<table cellpadding="5" cellspacing="1" border="0" class="selectform">
<th class="list" colspan="3">
select from
</th>
<tr valign="top">
<td colspan="3">
write to
</td>
</tr>
<tr valign="top">
<td colspan="3">
 
</td>
</tr>
<tr valign="top" >
<td class="selectform">
Task list
</td>
<td>
 
</td>
<td class="selectform">
<label>Included tasks</label>
</td>
</tr>
<tr valign="top">
<td class="selectform" rowspan="2">
<select name="select[]" size="30" multiple class="fixedWidth">
<?php foreach ($objectslist as $object)
{?>
<option><?=$object['name']." - " .$object['description']?></option>
<?php } ?>
</td>
<td valign="center" align="center">
<input type="submit" name="add" value=">>" >
</td>
<td class="selectform" rowspan="2">
<select name="addto[]" size="30" multiple class="fixedWidth">
<?php foreach ($included_tasks as $included_task)
{?>
<option><?=$included_task?></option>
<?php } ?>
</td>
</tr>
<tr valign="top">
<td>
<input type="submit" name="remove" value="<<" >
</td>
</tr>
</table>
</form>
<?php page_footer(); ?>feyd | Please use
Code: Select all
tags when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]