smitho Posted January 2, 2008 Share Posted January 2, 2008 I've done a search and although the process of passing data from a popup back to the main window has been discussed I have not been able to get this to work. I have the process in 3 parts. boxesPage1.php gives the user 4 check boxes to choose from. boxesPage2.php displays the choices made in a text field as an array. This page also has an update link to allow user to edit the choice they made. boxesPage3.php is a popup that the user can use to change the box selection they made and then take them back to boxesPage2.php. It's seems to be working until I get to the part where the changes in the popup are applied back to the boxesPage2.php. Although I don't get the updated results if I click on the update link a second time the popup will appear with the altered choices which mean I am holding the choices I just need to pass then back to the results page (2). If anyone could point out where I'm going wrong it would be appreciated. boxesPage1.php <?php //Set the boxes to unchecked $box1='unchecked'; $box2='unchecked'; $box3='unchecked'; $box4='unchecked'; ?> <!--create form--> <form enctype="multipart/form-data" method="post" action="boxesPage2.php"> <table width="0%" border="0"> <tr> <td><input type="checkbox" name="box1[]" value="box1"<?PHP print $box1; ?>>Checkbox1</td> <td><input type="checkbox" name="box1[]" value="box2"<?PHP print $box2; ?>>Checkbox2</td> <td><input type="checkbox" name="box1[]" value="box3"<?PHP print $box3; ?>>Checkbox3</td> <td><input type="checkbox" name="box1[]" value="box4"<?PHP print $box4; ?>>Checkbox4</td> </tr> </table> <br> <br> <input name="check" type="submit" id="send" value="Send File" /> <label></label> </form> boxesPage2.php <?php //start session to capture the choices made in the first screen and pass them on the update screen. session_start(); if (isset($_POST["check"])) { $box=$_POST["box1"]; //as a normal var $box_count=count($box); // count how many values in array foreach ($box as $cat) { echo $cat." - "; } //check the array echo "<hr>"; } echo "<br>"; $_SESSION['boxes']=$box; ?> <!--display the choices--> <form action="checkmeta.php" method="post" enctype="multipart/form-data" name="checklist"> <label>Choice <input name="boxid" type="text" id="boxid" value="<?php foreach ($box as $cat) {echo $cat." - ";}?>" /> </label> <a href="boxesPage3.php<?php echo htmlspecialchars(SID); ?>" onclick= "window.open('boxesPage3.php', 'window_name', 'width = 800, height = 250');return false;">UPDATE BOXES</a> </form> boxesPage3.php <!--JS to close the popup and go back to the second screen--> <script language="JavaScript"> function refreshParent() { window.opener.location.href = window.opener.location.href; if (window.opener.progressWindow) { window.opener.progressWindow.close() } window.close(); } </script> <?php //get the choices made and shown in the second screen session_start(); $box1='unchecked'; $box2='unchecked'; $box3='unchecked'; $box4='unchecked'; $box = $_SESSION['boxes']; //check the boxes if they were checked or not. foreach ($box as $value) { if($value == 'box1'){ $box1='checked'; } if($value == 'box2'){ $box2='checked'; } if($value == 'box3'){ $box3='checked'; } if($value == 'box4'){ $box4='checked'; } } $_SESSION['boxes']=$box; ?> <form enctype="multipart/form-data" method="post" action="boxesPage2.php"> <table width="0%" border="0"> <tr> <td><input type="checkbox" name="box1[]" value="box1"<?PHP print $box1; ?>>Checkbox1</td> <td><input type="checkbox" name="box1[]" value="box2"<?PHP print $box2; ?>>Checkbox2</td> <td><input type="checkbox" name="box1[]" value="box3"<?PHP print $box3; ?>>Checkbox3</td> <td><input type="checkbox" name="box1[]" value="box4"<?PHP print $box4; ?>>Checkbox4</td> </tr> </table> <br> <input name="check" type="submit" id="send" value="Send File" onclick="refreshParent(<?php $_SESSION['boxes']=$box;?>)" /> <label></label> </form> Link to comment https://forums.phpfreaks.com/topic/84056-using-sessions-to-capture-checkbox-options-and-pass-then-to-a-popup/ Share on other sites More sharing options...
smitho Posted January 2, 2008 Author Share Posted January 2, 2008 OK one step closer. On boxesPage2.php after if (isset($_POST["check"])) { ........ } I've added. else { $box = $_SESSION['boxes2']; } echo "<br>"; $_SESSION['boxes']=$box; print_r($box); To get this data on boxesPage3.php I've added this line. $_SESSION['boxes2']=$box; I don't get the error Notice: Undefined variable: box in ....on line (which was ->$_SESSION['boxes']=$box;) But to get it to work I have to click on the update link make my change in the popup submit to go back to the main window (no change) click on the update link a second time and just click on the submit button again then the change has taken place. Should this not occur the first time? Link to comment https://forums.phpfreaks.com/topic/84056-using-sessions-to-capture-checkbox-options-and-pass-then-to-a-popup/#findComment-427846 Share on other sites More sharing options...
smitho Posted January 2, 2008 Author Share Posted January 2, 2008 Can anyone tell me if there is a way to check that once I click on the submit button on the popup that the check boxes I've selected are captured. I don't understand why it doesn't apply the first time I change the options in the popup but it does the second time I update them. Any suggestion would be appreciated. Link to comment https://forums.phpfreaks.com/topic/84056-using-sessions-to-capture-checkbox-options-and-pass-then-to-a-popup/#findComment-428026 Share on other sites More sharing options...
smitho Posted January 2, 2008 Author Share Posted January 2, 2008 bump Link to comment https://forums.phpfreaks.com/topic/84056-using-sessions-to-capture-checkbox-options-and-pass-then-to-a-popup/#findComment-428667 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.