...

View Full Version : Preserving form data on reload



finstah1
05-05-2006, 08:58 PM
I have a form with input, radio, select and checkboxes and am trying to get the data to stay populated I have the input box working with this to preserve the data



<input tabindex="4" type="text" name="city" id="city" value="<? echo ( isset( $_POST['city'] ) && $_POST['city'] ) ? $_POST['city']:""; ?>" size="30" maxlength="30" />


but does anyone know how to preserve what the user entered for select dropdowns, radio buttons and checkboxes? My checks disappear and my dropdowns revert back to "Choose one"

lansing
05-05-2006, 09:48 PM
Is it like a reference page where the user can choose preference via Check box & Radio buttons & then view the page later & you want the options he chose to be chosen?

This might help...
http://codingforums.com/showthread.php?t=81738

finstah1
05-08-2006, 02:36 PM
that looks like it. :) will this work for both radio and checkboxes?

degsy
05-08-2006, 02:53 PM
<?php
$myChk = 'yes';
$mySel = 'Blue';
?>
<form name="form1" method="post" action="">
<p>
<input <?php if (!(strcmp($myChk,"yes"))) {echo "checked";} ?> type="checkbox" name="checkbox" value="yes">
</p>
<p>
<select name="select">
<option value="Red" <?php if (!(strcmp("Red", $mySel))) {echo "SELECTED";} ?>>Red</option>
<option value="Green" <?php if (!(strcmp("Green", $mySel))) {echo "SELECTED";} ?>>Green</option>
<option value="Blue" <?php if (!(strcmp("Blue", $mySel))) {echo "SELECTED";} ?>>Blue</option>
</select>
</p>
</form>

lansing
05-08-2006, 11:53 PM
<?php
$myChk = 'yes';
$mySel = 'Blue';
?>
<form name="form1" method="post" action="">
<p>
<input <?php if (!(strcmp($myChk,"yes"))) {echo "checked";} ?> type="checkbox" name="checkbox" value="yes">
</p>
<p>
<select name="select">
<option value="Red" <?php if (!(strcmp("Red", $mySel))) {echo "SELECTED";} ?>>Red</option>
<option value="Green" <?php if (!(strcmp("Green", $mySel))) {echo "SELECTED";} ?>>Green</option>
<option value="Blue" <?php if (!(strcmp("Blue", $mySel))) {echo "SELECTED";} ?>>Blue</option>
</select>
</p>
</form>
If you are quering from a DB then you just set it like this?
$search = mysql_query("SELECT * FROM table WHERE customers_id= '$id' ");
while ($line = mysql_fetch_array($search)) {
$myChk = $line["column_name"];
$mySel = $line["column_name"];
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum