Jump to content


Photo

sessions vs. posted values


  • Please log in to reply
9 replies to this topic

#1 rbragg

rbragg
  • Members
  • PipPipPip
  • Advanced Member
  • 176 posts

Posted 23 October 2006 - 02:13 PM

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:

<?php
$sticky_rbRaised = ( (isset($_POST['rbRaised'])) && ($_POST['rbRaised'] == 'raised printing') )?' checked="checked" ':' '; # maintains entry
echo '<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 entry
echo '<input type="radio" ' . $sticky_rbFlat . ' name="rbFlat" id="rbFlat" value="flat printing" onClick="clear_raised();" />'; # displays radiobutton
?>

On Page 2, I am echoing entries so that the user may confirm them:

<?php 
$rbRaised=$_SESSION['rbRaised'];
$rbFlat=$_SESSION['rbFlat'];
$color=$_SESSION['rbColor'];
	
if( !empty($rbRaised) )	
{
	echo "$rbRaised"; 													
}
	
if( !empty($rbFlat) )	
{
	echo "$rbFlat : $color"; 													
}
?>

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?

#2 rbragg

rbragg
  • Members
  • PipPipPip
  • Advanced Member
  • 176 posts

Posted 23 October 2006 - 07:07 PM

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?

#3 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 23 October 2006 - 08:49 PM

How are you assigning the values to the session variable.  Can you show me the code for page 1?

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#4 rbragg

rbragg
  • Members
  • PipPipPip
  • Advanced Member
  • 176 posts

Posted 23 October 2006 - 09:04 PM

Thanks so much for replying!

atop Page 1:

<?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';
}
?>



#5 rbragg

rbragg
  • Members
  • PipPipPip
  • Advanced Member
  • 176 posts

Posted 24 October 2006 - 12:29 PM

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.

#6 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 24 October 2006 - 03:33 PM

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?

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#7 rbragg

rbragg
  • Members
  • PipPipPip
  • Advanced Member
  • 176 posts

Posted 24 October 2006 - 04:09 PM

LOL! Well, that is why I said this:

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.


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):
<?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
	} 
	?>

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. 
???

#8 rbragg

rbragg
  • Members
  • PipPipPip
  • Advanced Member
  • 176 posts

Posted 24 October 2006 - 09:07 PM

I was able to workaround this problem by unsetting these variables which have alternatives on Page 1.

<?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';
}

?>


#9 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 25 October 2006 - 10:34 AM

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.

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#10 rbragg

rbragg
  • Members
  • PipPipPip
  • Advanced Member
  • 176 posts

Posted 25 October 2006 - 12:15 PM

Thank you for your help!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users