For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > May 2006 > retaiing values when resubmitting a page









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author retaiing values when resubmitting a page
Ian Davies

2006-05-29, 7:58 am

Hello

does anyone know how I can retain values of a radio button and text in a
text box on a page when I use $_SERVER['PHP_SELF'] to requery a page? Im
sure Ive seen this done before but cant find the code

Thanks
Ian


dimo414

2006-05-29, 6:58 pm

inside the tag for the textarea, the value attribute should be set to a
snippet of php which echo's (or prints) the value of the posted
variables. If nothing has been submitted, then nothing will be echoed,
and the box will appear empty. if something was submitted, it will be
echoed back into the box. A similar idea applies to radio and
checkboxes, but it's SLIGHTLY more dificult because you have to
determine (using if conditionals) which button it should be set to.

Ian Davies

2006-05-29, 6:58 pm

thanks
I found a solution. posted below incase anyone else is interested

at top of page
session_start();
$_SESSION['mytextbox'] = trim($_POST['mytextbox']);
$_SESSION['myradiobutton'] = trim($_POST['myradiobutton']);

for the textbox
input name="mytextbox" type="text" value="<?php echo
$_SESSION['mytextbox'];?>"

for the radiobutton
input <?php if (!(strcmp($_SESSION['myradiobutton'],"1"))) {echo "CHECKED";}
?> name="myradiobutton" type="radio" value="yourcheckedvaluehere"

ian


"dimo414" <dimo414@gmail.com> wrote in message
news:1148936810.408821.112400@j33g2000cwa.googlegroups.com...
> inside the tag for the textarea, the value attribute should be set to a
> snippet of php which echo's (or prints) the value of the posted
> variables. If nothing has been submitted, then nothing will be echoed,
> and the box will appear empty. if something was submitted, it will be
> echoed back into the box. A similar idea applies to radio and
> checkboxes, but it's SLIGHTLY more dificult because you have to
> determine (using if conditionals) which button it should be set to.
>



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com