I'm having an issue with the following code snippet. What I'm trying to do is append a list of states together when multiples are selected. So, if they select Alabama, it should just return AL. If they select Alabama and Georgia, then it should display AL,GA. (note the comma in between states).
The problem I'm having is that if a user hits their back button and then SUBMIT again, it concatenates everything. So, for the first time it will display AL,GA,FL. If they hit back and SUBMIT again, it'll display AL,GA,FLAL,GA,FL
How can I prevent this from happening? Thanks.
The problem I'm having is that if a user hits their back button and then SUBMIT again, it concatenates everything. So, for the first time it will display AL,GA,FL. If they hit back and SUBMIT again, it'll display AL,GA,FLAL,GA,FL
How can I prevent this from happening? Thanks.
Code:
if (empty($_POST['submit']) ) {
echo '<form name="test" action="test.php" method="POST">
<select multiple name="opstates[]" size="3">
<option value="AL" id="AL">Alabama</option>
<option value="FL" id="FL">Florida</option>
<option value="GA" id="GA">Georgia</option>
</select><input type="submit" name="submit" value="Submit"></form>';
} else {
extract($_REQUEST);
$s = "";
foreach ($opstates as $v) {
if (strlen($s) > 0) { $s = $s.','; }
$s = $s.$v;
echo $s;
}
}