Jump to content

sessions vs. posted values


rbragg

Recommended Posts

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 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
?>[/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?
Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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. 
???
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

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