By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,664 Members | 1,643 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,664 IT Pros & Developers. It's quick & easy.

Form in 2 steps - Preserving button radio

P: n/a
Hello. Yes, already ask but no answers for this little problem.
I've got a form and 3 steps or page for the same form. If we come back
to the first page, the states of button radio are lost.

First page (form1.php)
<?
$gender=$_POST['gender'];
if(isset($_POST['gender'])){
$statusm="";
$statusf="";
if($_POST['gender']=="M"){$statusm="checked"}
else{$statusf="checked"}
?>

<Form... action="form2.php">
....
<input name="gender" type="radio" id="male" value="M"<?php echo
$statusm
?>M
<input name="gender" type="radio" id="female" value="F"<?php echo
$statusf ?>>F
....
</Form>

Second page (form2.php)
<?
$Gender=$_POST['gender'];
?>

<Form... action="form1.php">
....
<input name="gender" type="hidden" id="gender" value="<? echo $gender ?
>" />
....
</Form>

But it doesn't work!!!

A solution could be with "session_start()" and $_cookie but I don't
know how to do it!

If anybody could write me all I need on the two pages with a little
exemple?? (The same problem come with the checkox or choise with
dynamic menu!) Thanks, pascal

Feb 22 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
elia schreef:
Hello. Yes, already ask but no answers for this little problem.
I've got a form and 3 steps or page for the same form. If we come back
to the first page, the states of button radio are lost.
A solution could be with "session_start()" and $_cookie but I don't
know how to do it!

One way to do it.

foreach ($_POST as $key=>$val)
{
echo '<input type = "hidden" name="'.htmlentities($key).'"
value="'.htmlentities($val).'" />';
}

--
Arjen
http://www.hondenpage.com - Mijn site over honden
Feb 22 '07 #2

P: n/a
Thanks but it's doesn't work for button radio... pascal

Feb 22 '07 #3

P: n/a
On 22 Feb, 07:45, "elia" <jos...@pcl.chwrote:
Hello. Yes, already ask but no answers for this little problem.
I've got a form and 3 steps or page for the same form. If we come back
to the first page, the states of button radio are lost.

First page (form1.php)
<?
$gender=$_POST['gender'];
if(isset($_POST['gender'])){
$statusm="";
$statusf="";
if($_POST['gender']=="M"){$statusm="checked"}
else{$statusf="checked"}
?>

<Form... action="form2.php">
...
<input name="gender" type="radio" id="male" value="M"<?php echo
$statusm
?>M
<input name="gender" type="radio" id="female" value="F"<?php echo
$statusf ?>>F
...
</Form>

Second page (form2.php)
<?
$Gender=$_POST['gender'];
?>

<Form... action="form1.php">
...
<input name="gender" type="hidden" id="gender" value="<? echo $gender ?>" />

...
</Form>

But it doesn't work!!!

A solution could be with "session_start()" and $_cookie but I don't
know how to do it!

If anybody could write me all I need on the two pages with a little
exemple?? (The same problem come with the checkox or choise with
dynamic menu!) Thanks, pascal
When re-writing the button code on form1 include CHECKED on the one
that should be selected

Feb 22 '07 #4

P: n/a
elia schreef:
Thanks but it's doesn't work for button radio... pascal
offcourse it does.
on page 1
echo '<input type = "radio name="gender" value="female" />';
echo '<input type = "radio name="gender" value="male" />';

on page 2
foreach ($_POST as $key=>$val)
{
echo '<input type = "hidden" name="'.htmlentities($key).'"
value="'.htmlentities($val).'" />';
}
on page 3
// do this any way u like. This will give an error in safe mode.
$checked[$_POST['gender']]='checked="checked"';
echo '<input type = "radio" name="gender" value="female"
'.$checked['female'].'/>';
echo '<input type = "radio" name="gender" value="male"
'.$checked['male'].'/>';
echo 'Your gender is'.$_POST['gender'];

if it doen't work post the output of var_dump($_POST); did you set your
form right ?

--
Arjen
http://www.hondenpage.com - Mijn site over honden
Feb 22 '07 #5

P: n/a
elia wrote:
Hello. Yes, already ask but no answers for this little problem.
I've got a form and 3 steps or page for the same form. If we come back
to the first page, the states of button radio are lost.

First page (form1.php)
<?
$gender=$_POST['gender'];
if(isset($_POST['gender'])){
$statusm="";
$statusf="";
if($_POST['gender']=="M"){$statusm="checked"}
else{$statusf="checked"}
?>

<Form... action="form2.php">
...
<input name="gender" type="radio" id="male" value="M"<?php echo
$statusm
?>M
<input name="gender" type="radio" id="female" value="F"<?php echo
$statusf ?>>F
...
</Form>

Second page (form2.php)
<?
$Gender=$_POST['gender'];
?>

<Form... action="form1.php">
...
<input name="gender" type="hidden" id="gender" value="<? echo $gender ?
>" />
...
</Form>

But it doesn't work!!!

A solution could be with "session_start()" and $_cookie but I don't
know how to do it!

If anybody could write me all I need on the two pages with a little
exemple?? (The same problem come with the checkox or choise with
dynamic menu!) Thanks, pascal
Look at your source code. I think you'll find this comes out to

<input name="gender" type="radio" id="male" value="M"CHECKEDM

Note the lack of a space between "M" and CHECKED.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Feb 22 '07 #6

P: n/a
Extra!! All is ok, I had the same problem for the selected menu but is
ok now with the same code, thanks a lot for all!! Pascal

Feb 23 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.