Jump to content

pass hidden variable to another form


angel777

Recommended Posts

Use sessions, that way you can maintain the information through to the last page. It would be a lot easier than trying to pass every value from every page through hidden inputs.

 

Give an example of your form (code)...it's hard to tell what your trying to do by your vague description.

Link to comment
Share on other sites

[u][b]Form1[/b][/u]
<form  action="Form3.php" method="post">
<p>2) Do you  feel more self-confident than usual?</p>
<ul>
<Input  type="radio button" name="choice" value="1"
onclick="checkTotal()">Yes <br>
<Input  type="radio button" name="choice" value="0"
onclick="checkTotal()">No <br>

</ul>
<input type="submit" value="Submit">
</form>

[u][b]Form3.php[/b][/u]

<form  action="Form4.php" method="post">
<p>3) Do you happy?</p>
<ul>
<Input  type="radio button" name="choice" value="1"
onclick="checkTotal()">Yes <br>
<Input  type="radio button" name="choice" value="0"
onclick="checkTotal()">No <br>
</ul>
<input type="submit" value="Submit">
</form>

 

how do i pass the from Form1.php to Form3.php to Form4.php..Form5.php..Form6.php ( hidden)

where finally i want to sum up the all value from all pages..

 

 

 

 

Link to comment
Share on other sites

why not just carry them in sessions?  so on each page you have

<?php
if(!empty($_POST['choice'])){
$_SESSION['FormData']['Choice'][] = $_POST['choice'];
}
?>

then on your final page just say do this again to add it to that session array (pre any headers being sent)

and use that array to work off of.

Link to comment
Share on other sites

i tried.. but the array value are the same..  it never add the second value..

 

 

<form name="listForm" action="test3.php" method="post">

 

<p>2) Do you  feel more self-confident than usual?</p>

 

<ul>

<Input type = 'Radio' Name ='mania_2' value= '1' <?PHP print $male_status; ?>>Yes <br>

<Input type = 'Radio' Name ='mania_2' value= '0' <?PHP print $female_status; ?>>No

 

<input type="submit" value="Submit">

</form>

 

test3.php

<body>

<?php

if(!empty($_POST['mania_3'])){

$_SESSION['FormData']['mania_3'][] = $_POST['mania_3'];

 

print_r($_SESSION['FormData']);

 

}

the array here never change ..??

?>

 

<form name="listForm" action="test4.php" method="post">

<p>2) Do you  feel more self-confident than usual?</p>

 

<Input type = 'Radio' Name ='mania_4' value= '1' <?PHP print $male_status; ?>>Yes <br>

<Input type = 'Radio' Name ='mania_4' value= '0' <?PHP print $female_status; ?>>No

<input type="submit" value="Submit">

 

</ul>

</form>

</body>

 

 

test4.php

<body>

<?php

if(!empty($_POST['mania_3'])){

$_SESSION['FormData']['mania_3'][] = $_POST['mania_3'];

 

print_r($_SESSION['FormData']);

 

}

 

?>

 

<p>2) Do you  haha?</p>

<Input type = 'Radio' Name ='mania_4' value= '1' <?PHP print $male_status; ?>>Yes <br>

<Input type = 'Radio' Name ='mania_4' value= '0' <?PHP print $female_status; ?>>No

</body>

 

 

 

Link to comment
Share on other sites

i tried.. but the array value are the same..  it never add the second value..

 

<form name="listForm" action="test3.php" method="post">

<p>2) Do you  feel more self-confident than usual?</p>

<ul>
<Input type = 'Radio' Name ='mania_2' value= '1' <?PHP print $male_status; ?>>Yes <br>
<Input type = 'Radio' Name ='mania_2' value= '0' <?PHP print $female_status; ?>>No

<input type="submit" value="Submit">
</form>

[b]test3.php[/b]
<body>
<?php
if(!empty($_POST['mania_2'])){
$_SESSION['FormData']['mania_2'][] = $_POST['mania_2'];

print_r($_SESSION['FormData']);

}

?>

<form name="listForm" action="test4.php" method="post">
<p>2) Do you  feel more self-confident than usual?</p>

<Input type = 'Radio' Name ='mania_3' value= '1' <?PHP print $male_status; ?>>Yes <br>
<Input type = 'Radio' Name ='mania_3' value= '0' <?PHP print $female_status; ?>>No
<input type="submit" value="Submit">

</ul>
</form>
</body>


[b]test4.php[/b]
<body>
<?php
if(!empty($_POST['mania_3'])){
$_SESSION['FormData']['mania_3'][] = $_POST['mania_3'];

print_r($_SESSION['FormData']);
[b] the array here never change ..??[/b]

}

?>

<p>2) Do you  haha?</p>
<Input type = 'Radio' Name ='mania_4' value= '1' <?PHP print $male_status; ?>>Yes <br>
<Input type = 'Radio' Name ='mania_4' value= '0' <?PHP print $female_status; ?>>No
</body>

 

 

Link to comment
Share on other sites

the above array keep growing because i try to back to the previous page and clcik the radio button again..  how do i prevent that ?

 

also,

 

why my page3 fail to read this data from page 2

<Input type = 'Radio' Name ='mania_2' value= '1' <?PHP print $male_status; ?>>Yes <br>

<Input type = 'Radio' Name ='mania_2' value= '0' <?PHP print $female_status; ?>>No

<input type="submit" value="Submit">

 

 

i can only read when the value is 1.. but when i click on "NO" the 0 value cannot bring to next page..

page3

<?php

if(!empty($_POST['mania_2'])){

$_SESSION['FormData']['mania_2'][] = $_POST['mania_2'];

 

print_r($_SESSION['FormData']);

}

?>

Link to comment
Share on other sites

$_SESSION['FormData']['mania_3'][]  //it show mania_3 is a  array

 

do

 

$_SESSION['FormData']['mania_3']

 

might help !!

 

the other things is you need to manage session properly .Else it will retain the values so once completed with work of session simply destroy your session at end.

 

Regards

Link to comment
Share on other sites

try

 

if(trim($_POST['mania_2']) != '' ){

$_SESSION['FormData']['mania_2'] = $_POST['mania_2'];

 

this will solve your problem 1 that it is not saving you NO values regaridng other problem about summing up you have to do proper session management.

 

i am not getting that how many values you can store in mania_2,mania_3 ???

 

regards

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.