rbragg Posted October 23, 2006 Share Posted October 23, 2006 Good morning! I have a Page 1 (form) and a Page 2 (confirm). On Page 1, the form submits to itself and I "include" my validation file. That file will redirect to Page 2 if everything is correct. So, on Page 1, I have 2 radiobuttons with 2 different names. I name them differently b/c I have another set of Rbs that are dependent on these. If need be, I can explain that later. Here are the RBs:[code]<?php$sticky_rbRaised = ( (isset($_POST['rbRaised'])) && ($_POST['rbRaised'] == 'raised printing') )?' checked="checked" ':' '; # maintains entryecho '<input type="radio" ' . $sticky_rbRaised . ' name="rbRaised" id="rbRaised" value="raised printing" onClick="clear_color();" />'; # displays radiobutton$sticky_rbFlat = ( (isset($_POST['rbFlat'])) && ($_POST['rbFlat'] == 'flat printing') )?' checked="checked" ':' '; # maintains entryecho '<input type="radio" ' . $sticky_rbFlat . ' name="rbFlat" id="rbFlat" value="flat printing" onClick="clear_raised();" />'; # displays radiobutton?>[/code]On Page 2, I am echoing entries so that the user may confirm them:[code]<?php $rbRaised=$_SESSION['rbRaised'];$rbFlat=$_SESSION['rbFlat'];$color=$_SESSION['rbColor']; if( !empty($rbRaised) ) { echo "$rbRaised"; } if( !empty($rbFlat) ) { echo "$rbFlat : $color"; }?>[/code]As you can see, I am printing session values rather than posted values. My problem is that values are passed over to the confirmation page correctly. But, if the user finds something he/she wants to change, presses the back button, makes changes, and resubmits ... the new value is carried over as well as the old one. Can someone help? Quote Link to comment https://forums.phpfreaks.com/topic/24842-sessions-vs-posted-values/ Share on other sites More sharing options...
rbragg Posted October 23, 2006 Author Share Posted October 23, 2006 You should be able to tell I'm a rookie at sessions. Should I use session_destroy(); somewhere on Page 2 even though I will be passing values to a 3rd page? Quote Link to comment https://forums.phpfreaks.com/topic/24842-sessions-vs-posted-values/#findComment-113322 Share on other sites More sharing options...
HuggieBear Posted October 23, 2006 Share Posted October 23, 2006 How are you assigning the values to the session variable. Can you show me the code for page 1?RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/24842-sessions-vs-posted-values/#findComment-113356 Share on other sites More sharing options...
rbragg Posted October 23, 2006 Author Share Posted October 23, 2006 Thanks so much for replying!atop Page 1:[code]<?php session_start();if( isset($_POST['confirm']) ) # if form is submitted{ foreach ($_POST as $key => $value) # put the values into session variables { if ($key != "confirm") { $_SESSION[$key] = $value; } } include 'bc_validate.php';}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/24842-sessions-vs-posted-values/#findComment-113368 Share on other sites More sharing options...
rbragg Posted October 24, 2006 Author Share Posted October 24, 2006 I should mention a reminder that my redirect to Page 2 is within my validation include.Should I assign them back to POST values on Page 2? This is why I am confused ... I'll need to pass them as session variables to a Page 3. Quote Link to comment https://forums.phpfreaks.com/topic/24842-sessions-vs-posted-values/#findComment-113601 Share on other sites More sharing options...
HuggieBear Posted October 24, 2006 Share Posted October 24, 2006 I think one of us is confused here.Radio buttons are usually composed of various buttons with the same name, but different values, allowing you to select only one of the options. From what you're showing me, it's indicating that you have two radio buttons, both with a different name, hence independent from each other. If this is the case, then surely a checkbox is what you're after?RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/24842-sessions-vs-posted-values/#findComment-113673 Share on other sites More sharing options...
rbragg Posted October 24, 2006 Author Share Posted October 24, 2006 LOL! Well, that is why I said this:[quote]on Page 1, I have 2 radiobuttons with 2 different names. I name them differently b/c I have another set of Rbs that are dependent on these. If need be, I can explain that later.[/quote]rbFlat had another group of RBs associated with it called rbColor. rbColor can only be selected if rbFlat is selected. I had trouble with checking the validation of this, which is why I named the rbRaised and rbFlat differently. For your information, I also have this problem when I want to either echo the value of 1 group of RBs or a textfield in another place in my form. This problem seems to only take place when I use these if statements in my confirmation page. For example, say that only either rbBill or speed can have values and not both (ensured with some onClick functions on Page 1): [code]<?php $rbBill=$_SESSION['rbBill']; $speed=$_SESSION['speed']; if( !empty($rbBill) ) # if one of the radiobuttons are chosen { echo "$rbBill"; # then, print which one } if( !empty($speed) ) # if there is a value for Speed Chart { echo "Speed Chart: $speed"; # then, print the number } ?>[/code]If the user chooses a RB and then goes to the confirmation page, decides to change that, presses the back button, and instead fills out the speed textfield ... on the confirmation page will be the value of the RB that has been deselected AND the value of the textfield. ??? Quote Link to comment https://forums.phpfreaks.com/topic/24842-sessions-vs-posted-values/#findComment-113697 Share on other sites More sharing options...
rbragg Posted October 24, 2006 Author Share Posted October 24, 2006 I was able to workaround this problem by unsetting these variables which have alternatives on Page 1. [code]<?php session_start();if(isset($_POST['confirm']) ) { unset($_SESSION ['rbBill']); unset($_SESSION ['speed']); unset($_SESSION ['rbRaised']); unset($_SESSION ['rbFlat']); unset($_SESSION ['rbColor']); foreach ($_POST as $key => $value) { if ($key != "confirm") { $_SESSION[$key] = $value; } } include 'bc_validate.php';}?> [/code] Quote Link to comment https://forums.phpfreaks.com/topic/24842-sessions-vs-posted-values/#findComment-113864 Share on other sites More sharing options...
HuggieBear Posted October 25, 2006 Share Posted October 25, 2006 I'm glad it worked out ok. I see what you mean about the radio buttons but still feel it's been coded incorrectly.I can appreciate using javascript to make one set of options available only if another is selected, but you should still use the appropriate form element.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/24842-sessions-vs-posted-values/#findComment-114106 Share on other sites More sharing options...
rbragg Posted October 25, 2006 Author Share Posted October 25, 2006 Thank you for your help! Quote Link to comment https://forums.phpfreaks.com/topic/24842-sessions-vs-posted-values/#findComment-114152 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.