Jump to content

Debug Code for retaining selection


killdozer

Recommended Posts

I'm stuck trying to figure out why when I make a selection in drop down list of a php form, the selection does not stay when form is refreshed or re-displayed due to an pattern error of another field.

 

My array is

state_province = array(list of the states, and provinces)

field name in the label array is: "state" => "State",

Here is the code that I'm using:

 

echo "<form action='$_SERVER[php_SELF]' method='POST'>";

foreach($labels as $field => $label)

{

if($field == "state")

{

echo "<div class='province_state'><label for='state' size='15'>* Province/State</label><select>";

 

foreach($state_province as $state)

 

{

echo "<option value=$state";

if(@$_POST['state'] == $state)

  {

echo "selected='selected'";

  }

echo ">";

echo $state;

echo "</option>\n";

}

  echo "</select></div>\n";

 

}

 

 

Link to comment
https://forums.phpfreaks.com/topic/233241-debug-code-for-retaining-selection/
Share on other sites

Ok I changed it to this, but no change for the retention:

 

echo "<form action='$_SERVER[php_SELF]' method='POST'>";

foreach($labels as $field => $label)

{

if($field == "state")

{

echo "<div class='province_state'><label for='state' size='15'>* Province/State</label><select name='state' id='state'>";

 

foreach($state_province as $state)

 

{

echo "<option value= $state";

if(@$_POST['state'] == $state)

  {

echo "selected='selected'";

  }

echo ">";

echo $state;

echo "</option>\n";

}

  echo "</select></div>\n";

 

}

 

 

 

 

 

 

 

 

Your <select> doesn't have a name. Unless you make the <label> end after </select>, you'll need to set its name.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.