PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Is it possible to submit form results to 2 diffrent pages depending on selections or conditions made in the form?
It's a simple login form. NAME, EMAIL, PASSWORD. There is a password hint field in the database. I want to have the user enter NAME, EMAIL and PASSWORD to go to page A by using "SUBMIT" OR enter just NAME and EMAIL and get back a password hint (printed right on the login form) by using a second "GET HINT" submit button. I would like to use just one form so the user dosen't have to reenter the NAME, EMAIL twice.
<form method=POST action=<?=$send_data;?>
<input type="submit" value="Send to page A" name="page A">
<input type="submit" value="Send to page B" name="page B">
IF (isset($page A)) {
$send_data="page_A.php"
}
IF (isset($page B)) {
$send_data="page_B.php"
}
It kind of works, but runs through the form twice.(The second time actually sets the action. Any way to get "page_A.php" to function as a defualt action URL and go through on the first try? I don't care if the second choice runs the form again.
<?php
if (isset($page_B)) { // If page_B button has been clicked previously
$send_data = 'page_B.php';
} else { // If nothing has been clicked yet or page_A button has been clicked
$send_data = 'page_A.php';
}
echo '<form method="POST" action="'.$send_data.'">';
// REST OF FORM
echo '<input type="submit" value="Send to page A" name="page_A">';
echo '<input type="submit" value="Send to page B" name="page_B">';
?>
Although if the page_B button was clicked first time the action would be page_A still. It would probably be a better solution to have one form handling page with either an if..else statement or a switch in it that ran code based on which button had been pressed. It wouldn't be too difficult to check if the password box had been filled in and if it wasn't show the hint and if it had do the login authentication bit.
This is similar to what hob_goblin posted, just a little different. The easiest way I found to do this would be to submit to a single page and either give the buttons the same name and check the value or give the buttons different names and check to see which one isset(). I like using the isset() option better.
I've been screwin' with this for 8 hours straight. I finally gave up and went with rokamortis idea (I actually just shoved a whole copy of page A (picking up the hint value on the way) into page B and to the user it looks like you just updated Page A(except for the title). But on the surface it does have the 2 submits, and looks and acts like I wanted. I was so close, or so it felt. Using a conditional variable for the action= atrub. seems like it would be standard. Alas not. Maybe in a beta of 7.0.