1

I'm doing a Quiz project: The idea is to implement almost 25 questions in which each question occupies each HTML page with 4 radio buttons and a submit button and a reset button as well.On clicking the submit button it should take the user to the next page as well as submit the data to the server. How to achieve this dual behaviour?

I tried this:

<form action="cba.php" method="post">
    <a href="abc.html">
        <input type="submit" value="submit">
    </a>
</form>

But this does only one purpose: Acting as a link without submitting the data.

mplungjan
  • 169,008
  • 28
  • 173
  • 236

2 Answers2

1

If you just want to redirect the user after submitting the form, you can use :

header("Location: yourlink");

in the php script you called cba.php.

Otherwise, i'm not sure it is possible to redirect the user before sending him the php script page.

HReynaud
  • 54
  • 1
  • 9
0

As mentioned, it would be a smoother experiance to handle this via ajax, but it can be acheived in just php by creating a redirect in the form processing code (as mentioned in comments and a current answer).

I believe your issue is with the fact that the same proccessing code (cba.php) will be called every step of the way, so you need a way for each quiz section to define the next section.

This can be done with a hidden field instead of the link code you tried:

<form action="cba.php" method="post">
    <input type="hidden" name="next-page" value="abc.html">
    <input type="submit" value="submit">

</form>

Then i cba.php, you redirect to the value contained in this hidden field:

//save the data from the form, then
header("Location: " . $_POST['next-page']);
Steve
  • 20,703
  • 5
  • 41
  • 67