Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reload form showing previously filled values 1

Status
Not open for further replies.

miguelleeuwe

Programmer
Oct 17, 2007
242
NL
hello,

I have a form that's reloaded when I fill a country in a <select>, so I can limit the number of possible timezones which a have in another <select>. this works fine using a reload function that I found somewhere, but the problem I have is that all other previously filled values of the form are blanked... Can someone tell me how to do reload, showing all previous values?

TIA,
Miguel (newby)

<select style="width: 340px;" name="nac_pais"
class="estilo_input" onchange="reload(this.form)">
<option value=""></option>
<?php while($fila = mysql_fetch_array($paises))
if($fila['id_pais']==@$nac_pais)
{
echo "<option selected value='$fila[id_pais]'>$fila[descripcion]</option>"."<BR>";
}
else
{
echo "<option value='$fila[id_pais]'>$fila[descripcion]</option>";
}

this is the reload function:
---------------------
<script language="JavaScript">
function reload(form)
{
var val=form.nac_pais.options[form.nac_pais.options.selectedIndex].value;
self.location='registrar_02_ES.php?nac_pais=' + val;
}
</script>
}


regards,
Miguel L.
 
For starters you would need to modify your logic. Basically you need to not reload your page, but actually submit it, so PHP can store the values in a Session variable. Then they can be used to re-populate your form elements with the filled in information.

Your other option is to use AJAX to modify your drop down. That way you avoid reloading the page at all

As it is: your current logic does not allow any way to save the filled in values.





----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
thank you very much for your answer.
I'm doing things the way I do, because my client wants to populate the timezones, after having filled in the country, without having to push any button or link.
Is there a way I can do a 'submit' instead of calling to my reload() 'automatically'?

sorry for my ignorance.
thanks,
Miguel


regards,
Miguel L.
 
Yup. you can use your same JS function to submit the form instead of reloading, and then have PHP store the values for future use using sessions.

Code:
<?PHP
[green]/*Call sesion_start */[/green]
session_start();

if(!isset($_SESSION['formvalues'])) [green]/*Check for theexistance of a session variable, if the variable is not present make one*/[/green]
{$_SESSION['formvalues']="";}

[green]/* Store all values from the posted form in the session variable*/[/green]

foreach($_POST as $inputname => $value){
$_SESSION['formvalues'][$inputname]=$value;
}
	


?>

<script>
[green]/*Javascript function to add the value of the drop down, and submit the form*/[/green]
function sub_form(choice){
myform.action='savevalues.php?param=' + choice.value;
myform.submit();
}
</script>
<form action="savevalues.php" method="POST" name=myform>
[green]/* check session variables to repopulate the textboxes if it does not exist leave blank*/[/green]
<input type="text" name="boxone" value="<?PHP if(isset($_SESSION['formvalues']['boxone'])) echo $_SESSION['formvalues']['boxone']; ?>">
<input type="text" name="boxtwo" value="<?PHP if(isset($_SESSION['formvalues']['boxtwo'])) echo $_SESSION['formvalues']['boxtwo']; ?>">
<input type="text" name="boxthree" value="<?PHP if(isset($_SESSION['formvalues']['boxthree'])) echo $_SESSION['formvalues']['boxthree']; ?>">
<input type="text" name="boxfour" value="<?PHP if(isset($_SESSION['formvalues']['boxfour'])) echo $_SESSION['formvalues']['boxfour']; ?>">

<select name="make" onChange="sub_form(this);">
<?PHP
foreach($makes as $make){
?>
[green]/*Dynamic generation of drop down to illustrate how to set the selected option. */[/green]
<option value="<?PHP echo $make ?>"  <?PHP if(isset($_SESSION['formvalues']['make']) && $_SESSION['formvalues']['make']==$make){ echo 'selected=selected';} ?> ><?PHP echo $make; ?></option>
<?PHP
}
?>
</select>
<input type="submit" name='submitname' value="Process">
</form>



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
thank you very much vacunita, this really helped me out!

regards,
Miguel L.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top