angel777 Posted January 25, 2008 Share Posted January 25, 2008 if i have 5 pages .. each page php with radio button.. how do i sum up the total value of radio button by passing the value in hidden form? Quote Link to comment https://forums.phpfreaks.com/topic/87699-pass-hidden-variable-to-another-form/ Share on other sites More sharing options...
pocobueno1388 Posted January 25, 2008 Share Posted January 25, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/87699-pass-hidden-variable-to-another-form/#findComment-448576 Share on other sites More sharing options...
angel777 Posted January 25, 2008 Author Share Posted January 25, 2008 [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.. Quote Link to comment https://forums.phpfreaks.com/topic/87699-pass-hidden-variable-to-another-form/#findComment-448582 Share on other sites More sharing options...
cooldude832 Posted January 25, 2008 Share Posted January 25, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/87699-pass-hidden-variable-to-another-form/#findComment-448583 Share on other sites More sharing options...
angel777 Posted January 25, 2008 Author Share Posted January 25, 2008 how do i display the data of that array ? Quote Link to comment https://forums.phpfreaks.com/topic/87699-pass-hidden-variable-to-another-form/#findComment-448587 Share on other sites More sharing options...
priti Posted January 25, 2008 Share Posted January 25, 2008 If you want to print the $_SESSION values then use print_r($_SESSION); and if only formdata choice then print_r($_SESSION['FormData']); Regards Quote Link to comment https://forums.phpfreaks.com/topic/87699-pass-hidden-variable-to-another-form/#findComment-448589 Share on other sites More sharing options...
angel777 Posted January 25, 2008 Author Share Posted January 25, 2008 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> Quote Link to comment https://forums.phpfreaks.com/topic/87699-pass-hidden-variable-to-another-form/#findComment-448604 Share on other sites More sharing options...
angel777 Posted January 25, 2008 Author Share Posted January 25, 2008 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> Quote Link to comment https://forums.phpfreaks.com/topic/87699-pass-hidden-variable-to-another-form/#findComment-448605 Share on other sites More sharing options...
kenrbnsn Posted January 25, 2008 Share Posted January 25, 2008 You need to put <?php session_start(); ?> at the start of each script. Ken Quote Link to comment https://forums.phpfreaks.com/topic/87699-pass-hidden-variable-to-another-form/#findComment-448614 Share on other sites More sharing options...
angel777 Posted January 25, 2008 Author Share Posted January 25, 2008 thanks.. but why the array keep growing ??.. in one page i only have only answer Array ( [mania_2] => Array ( [0] => 1 [1] => 1 [2] => 1 [3] => 1 [4] => 1 [5] => 1 ) [mania_3] => Array ( [0] => 1 [1] => 1 [2] => 1 ) ) how do i sum up the value? Quote Link to comment https://forums.phpfreaks.com/topic/87699-pass-hidden-variable-to-another-form/#findComment-448618 Share on other sites More sharing options...
angel777 Posted January 25, 2008 Author Share Posted January 25, 2008 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']); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/87699-pass-hidden-variable-to-another-form/#findComment-448621 Share on other sites More sharing options...
priti Posted January 25, 2008 Share Posted January 25, 2008 $_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 Quote Link to comment https://forums.phpfreaks.com/topic/87699-pass-hidden-variable-to-another-form/#findComment-448622 Share on other sites More sharing options...
angel777 Posted January 25, 2008 Author Share Posted January 25, 2008 putting array is because i need to sum up the value at the end.. 1) when click on the "NO" the value 0 never bring to next page. 2) how to sum up the value Quote Link to comment https://forums.phpfreaks.com/topic/87699-pass-hidden-variable-to-another-form/#findComment-448627 Share on other sites More sharing options...
priti Posted January 25, 2008 Share Posted January 25, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/87699-pass-hidden-variable-to-another-form/#findComment-448640 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.