2

I'm working on a database-driven quiz that lets users select a series of answers, then submit the results via a form. It was working great, when it suddenly blew up, and I haven't been able to find the problem.

So before I get into the more complex stuff, I'd like to go back to square one and just make something simple work - like passing a hidden value to another page that echoes that value.

Here's the code for my first page @ mysite/form.php:

<html>
<head>
</head>
<body>

<!-- g1/form.php -->
<div id="quiz" rel="key">
  <form action="form2.php" method="post" id="quiz">
    <input type="hidden" name="PreviousURL" id="url" />
    <input type="submit" value="Submit Quiz" />
  </form>
</div><!-- quiz-container -->

</body>
</html>

And here's the code for the second page:

<html>
<head>
</head>
<body>

<?php ini_set('display_errors', 1);

if ($_SERVER['REQUEST_METHOD'] == 'POST') {

echo $_POST['PreviousURL'];
}
echo 'XXX';
?>

</body>
</html>

I also tried moving the closing bracket, like this:

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
}

echo $_POST['PreviousURL'];
echo 'XXX';

In both cases, when I click the submit button and am forwarded to form2.php, I see "XXX," but there's no value for $_POST['PreviousURL'].

I must have accidentally deleted or modified something, because it seems so simple, and it worked fine before. Can anyone tell me what the problem is?

1 Answers1

2

there isn't a value for the hidden input.

In your form script you have missed out the value="" from the hidden input. This is the reason why nothing is displaying on the second page.

Johnny
  • 319
  • 1
  • 14
  • 1
    Wow, I don't know how I deleted that. Do you know offhand what value I should put inside value="" so that it captures the page's URL? –  Feb 12 '16 at 02:26
  • @DavidBlomstrom sure you could use this [grab url](http://stackoverflow.com/questions/16198790/get-url-path-in-php) but it would be easier if you defined the page in a variable before then echo the variable out in the value. but using the link I just sent is just as good. – Johnny Feb 12 '16 at 02:29