471,072 Members | 1,282 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,072 software developers and data experts.

retaiing values when resubmitting a page

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
May 29 '06 #1
3 1040
Ian Davies wrote:
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


The radio button and text are contained within a <form></form> tag set.
The <form> tag will have either method="GET" or method="POST"

If method="GET", you can read back the values using:
$foo = $_GET['foo'] where 'foo' is the name of your radio selector or
text field.

If method="POST", you can read back the values using:
$foo = $_POST['foo'];

-david-

May 29 '06 #2
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.

May 29 '06 #3
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" <di*****@gmail.com> wrote in message
news:11**********************@j33g2000cwa.googlegr oups.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.

May 29 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by James Baker | last post: by
6 posts views Thread by brian_mckracken | last post: by
5 posts views Thread by Miguel Dias Moura | last post: by
3 posts views Thread by Jeremy Ames | last post: by
5 posts views Thread by Hans Kesting | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.