help! post form won't submit...


#1

Hi everyone,

I’m trying to submit a form that contains a list of options and the list itself, and then to display the list with the selected option in the next page.
For some reason it’s working the first time but not on further attempts: do you know what could be the issue?

Thanks a lot!
jy

Here’s the code of the page :

<?php $list = $_POST['list']; $check = $_POST['check']; $year = $_POST['year']; if ($check != 1) { $check = 1; $list = " 2000 2001 2002 "; } else { $replace = " selected='selected'"; $by = ""; $list = str_replace($replace,$by,$list); $replace = $year . "'>"; $by = $year . "' selected='selected'>"; $list = str_replace($replace,$by,$list); } ?> <?php echo $list; echo ""; echo ""; ?>

#2

Hi,

I’m not completely certain of what you’re trying to do. But I can try with the ‘select’ you’re baking.

I was following $list around in your script. I’m kind of surprised you try to post HTML as a value of a form-element. The risk you run is that the ‘input’ tag closes and half of your ‘value’ is discarded as garbage HTML noise.

It seems to me you’re tryinf to get a ‘select’ statement that shows the previously selected value as selected.

have you tried:[php]
$years = array( 2000, 2001, 2002 );
$link = “<select name=“year”>\n”;

foreach( $years as $y )
{ $link .= “<option value=”$"";
if ( $y == $year )
{ $link .= ’ selected=“selected”’;
}
$link .= “>$y\n”;
}
$link .= " \n";
[/php]
This should give you a select with the previously chosen option selected.

Hope this helps you further.
o.