Hello Again everyone,
I have two forms on the same page, i have text input fields and the drop down boxes i created are auto submit boxes i created with javascript.
Now the problem is that when form 1 submits itself it resets form 2 and vica verca i am trying to get all the data on the page to stay in the boxes and i already use this method

<?php if($heat5 == 'Full system (elec to gas)') echo "selected = \"selected\"";?>

also when i move of the page say to jump back on i lose all the data again and i would like to keep this here too.
any suggestions bearing in mind am new to this so if you could provide an example i would be very greatful.

Member Avatar

You could put the variables into $_SESSION variables to keep them live over all pages as long as you've got session_start() at the beginning of every page.

$_SESSION['whatever'] = $_POST['whatever'];

You must kill the $_SESSION variables when no longer required:


To keep things tidy, you could put all post variables into a $_SESSION array, so you just have to kill off one variable at the end.

$_SESSION['form_data']['whatever1'] = $_POST['whatever1'];
$_SESSION['form_data']['whatever2'] = $_POST['whatever2'];
$_SESSION['form_data']['whatever3'] = $_POST['whatever3'];


so would that mean i would not need my current method and also how would i incorperate $_POST into my forms?

Member Avatar
 $what = $_SESSION['form']['whatever1']; 


<input type="text".... value="<?=$what;?>" />

would it be the same if it was a drop down box?

would it be the same if it was a drop down box?

yes a drop down is a single input, the value is the value of the chosen option, and fits nicely as one item in an array

<select name='man'>
<option value='bill'>bill</option>
<option value='brian'>brian</option>
<option value='barry'>barry</option>
<option selected value='AlmostBob'>Smart Alec</option>

would give in the $_POST array

$_POST =
[man] => 'AlmostBob'