Jump to content

Hidden Input, Image Buttons, SESSION Variables, and Self-submitting Forms


makamo66

Recommended Posts

I have a very simple survey at http://projectpotluck.com/survey/survey.php The survey is three pages long and on each page there is hidden variable which calculates how many bonus points the user has accumulated based on the number of good answers and passes the total to the next page. Instead of using a submit button, I am using an image button but I believe they are equivalent. For example for one of the survey pages I have the following code inside of the form tags:

 

<input type="hidden" name="bonus" value="<?php

$bonus == $_POST['bonus'];

if ($_SESSION['cooking'] == 'hobby')

$bonus += 1;

echo $bonus; ?>">

 

It collects the bonus posted from the previous page and adds one more bonus point if  $_SESSION['cooking'] == 'hobby' After it adds or doesn't add the bonus point, the hidden value gets submitted to the next page. For some reason this code used to work before I made some improvements to the code and after "improving" the code it stopped working. Before I improved the code I wasn't using SESSION variables or image buttons. Oh and another key change was that the form became self-submitting (that is, <form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">) and after being posted to itself, it gets sent to the next page via a header, that is it gets sent with header("Location: $url");. Any idea how this can be fixed?

 

Link to comment
Share on other sites

With the header redirect it won't send over the form variables without you attaching them to the url String then you have to adjust how they are obtained by using get or request instead of post. I would get rid of header ridirect on a multi-page form and do it the old way. Also make sure you have session_start() at the top of each page or it could drop sessions off. 

 

Post your full code here if you need more help (all code) with sensitive data edited.

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.