I have little experience of web development and don't know if what I am trying to do is possible, so here goes.
I have found some code that displays a multi-selectbox and have modified it slightly to use GET rather than POST so I can see what data is being passed in the address bar. Here's the code:
- Code: Select all
<?php
if(!isset($_GET['submit'])) # If this form has not been submitted
$chosen = array(3, 6, 2, 7); # Use the default
else # Otherwise
$chosen = $_GET['colors']; # Use what has been submitted
function showOptionsDrop($array, $active, $echo=true){
$string = '';
foreach($array as $k => $v){
if(is_array($active))
$s = (in_array($k, $active))? ' selected="selected"' : '';
else
$s = ($active == $k)? ' selected="selected"' : '';
$string .= '<option value="'.$k.'"'.$s.'>'.$v.'</option>'."\n";
}
if($echo) echo $string;
else return $string;
}
$colors = array('red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet', 'pink', 'black', 'white', 'silver', 'gold');
?>
<form name="colorform" action="" method="get">
<select name="colors[]" multiple="multiple" size="15">
<?php echo showOptionsDrop($colors, $chosen, true); ?>
</select><br />
<input type="submit" name="submit" value="submit" />
</form>
When I select one or more colours (yes, I am in the UK!) and click the Submit button, the address bar shows the index number(s) of the colour(s), rather than the colours themselves:
http://127.0.0.1/test.php?colors%5B%5D= ... mit=submit
My aim is to have a user select the colours and have them displayed on the page (so he can confirm the selection) and then submit them to a second page via another button.
I have tried IE8, Chrome and Firefox. I have xampp (with PHP version 5.3.
. I am not sure if what I am trying to do is impossible or if I am doing something wrong.It is possible to retrieve that actual colours, rather than their index?
I have been pulling my hair out for ages and am going around in circles!
Thank you for your time (and patience).


