Page 1 of 1

keep user input in form after a submit

Posted: Tue Mar 08, 2011 4:28 pm
by moran1409
hello all, i have a php form with multiple submits (one calculates price, one checks date and one submits the form and the data to mysql database)
when i hit calculate price, for example, the function works fine but all the fields are cleared and i would like for all the input to remain as the user sent.
here is part of the code (the form):

Code: Select all

<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">

	<fieldset>
	<legend ><span><a>video</span></a></legend>
	<ol>
	<li>
	<label for="hover_camera">hover camera</label>
	<input id="hover_camera" type="radio" name="hover_camera" value="yes" /><b>yes</b>
	<input id="hover_camera" type="radio" name="hover_camera" value="no"  /><b>no</b>
	</li>
	<li>
	<label for="video_photographers">video photographers</label>
	<input id="video_photographers" type="text" name="video_photographers" maxlength="1" size="1"/>
	</li>
	<li>
	<label for="video_edit">video edit</label>
	<input id="video_edit" type="radio" name="video_edit" value="short" /><b>short</b>
	<input id="video_edit" type="radio" name="video_edit" value="long" /><b>long</b>
	</li>
	<li>
	<label for="video_clip">video clip</label>
	     <select name="video_clip">
         <option value="no">no</option>
         <option value="regular">regular</option>
		 <option value="staged">staged</option>
      </select>
	</li>
	</ol>
	</fieldset><br />
	
	<fieldset align="right">  
    <legend><span><a>stills</span></a></legend> 
	<ol>
	<li>
	<label for="stills">stills</label>
	<input id="stills" type="text" name="stills" maxlength="1" size="1"  />
	</li>
	<li>
	<label for="increase">increase amount</label>
	<input id="increase" type="text" name="increase" maxlength="4" size="1" />
	</li>
	<li>
	<label for="magnets">magnets</label>
	<input id="magnets" type="text" name="magnets" maxlength="4" size="1" />
	</ol>
	</fieldset><br />
	
	<fieldset align="right">  
    <legend><span><a>albums</span></a></legend> 
	<ol>
	<li>
	<label for="digital_album">digital album</label>
	<input id="digital_album" type="radio" name="digital_album" value="yes" /><b>yes</b>
	<input id="digital_album" type="radio" name="digital_album" value="no" /><b>no</b>
	</li>
	<li>
	<label for="photo_album">photo album</label>
	<input id="photo_album" type="radio" name="photo_album" value="yes" /><b>yes</b>
	<input id="photo_album" type="radio" name="photo_album" value="no" /><b>no</b>
	</li>
	<li>
	<label for="small_digital_album">small digital album</label>
	<input id="small_digital_album" type="radio" name="small_digital_album" value="yes" /><b>yes</b>
	<input id="small_digital_album" type="radio" name="small_digital_album" value="no" /><b>no</b>	
	</li>
	</ol>
	</fieldset><br />
	
	<fieldset align="right">
	<ol>
	<li>
	<label for="comments">comments</label>																																																																																																																				
	<textarea id="comments" name="comments"></textarea><br /><br />
	</li>
	<li>
	<label for="price">price</label>
	 <td><input type="submit" id = "price" name="price" value="calculate price" /></td>
	</li>
	</ol>
	</fieldset><br />


<fieldset align="right">  
    <legend><span><a>choose date</span></a></legend> 
	<ol>
	<li>
	

	 
      <input type="submit" id="isavailable" name="isavailable" value="isavailable"  />
	  </li>
	  </ol>
  </fieldset>
  
  	<fieldset class="submit">
	<ol>
	<li>
	<input class="submit" type="submit" id="submit" name="submit" value="done!" />&nbsp;&nbsp;&nbsp; <input class="submit" type="reset" id="reset" name="reset" value="reset" />
	</li>
	</ol>
	</fieldset>  
  
</form>
thanks for the help

Re: keep user input in form after a submit

Posted: Tue Mar 08, 2011 4:44 pm
by Peec
use

Code: Select all

<input ... value="<?php isset($_POST['thepostname']) ? $_POST['thepostname'] : 'yes/no/whatever default value'?>" ... />
in each filed.

Re: keep user input in form after a submit

Posted: Wed Mar 09, 2011 9:36 am
by moran1409
i don't have any default values... it's supposed to be the user's choice...

Re: keep user input in form after a submit

Posted: Thu Mar 10, 2011 11:58 am
by moran1409
how can i use it with the radio buttons and the select box?
plus i inserted it like so in text box:

Code: Select all

	<input id="video_photographers" type="text" name="video_photographers" maxlength="1" size="1" value="<?php isset($_POST['video_photographers']) ? $_POST['video_photographers'] : '1'?>"/>
and it did not work... what am i doing wrong?
can you please answer with an example from my form?

Re: keep user input in form after a submit

Posted: Sat Mar 12, 2011 7:05 am
by moran1409
any other suggestions?