vozzek Posted April 9, 2008 Share Posted April 9, 2008 Hi all, Is it possible to have a form choose from two different possible actions (i.e. loading two different pages) based upon the value of a variable in php? For example, let's assume my form looks like this: <form ACTION="https://mywebsite.com/checkoutA.php" method="POST" name="pay_form" id="pay_form" onSubmit="return chkPayForm();" style="margin:0;"> Let's assume I have a variable called $total. If $total>0 I would like the form to process onto the page checkoutA.php But if the $total is not greater than zero, I would like the form to process onto the page checkoutB.php How would I go about this? Would I need to know the value of $total before the page gets to the html <form> code, and then optionally echo each possible outcome? Or is there an easier way? Thanks in advance, as always. Link to comment https://forums.phpfreaks.com/topic/100398-two-different-form-action-based-upon-a-variable/ Share on other sites More sharing options...
matto Posted April 9, 2008 Share Posted April 9, 2008 Would I need to know the value of $total before the page gets to the html <form> code, and then optionally echo each possible outcome? yes. Link to comment https://forums.phpfreaks.com/topic/100398-two-different-form-action-based-upon-a-variable/#findComment-513437 Share on other sites More sharing options...
vozzek Posted April 9, 2008 Author Share Posted April 9, 2008 Okay, was afraid of that. Thanks! Link to comment https://forums.phpfreaks.com/topic/100398-two-different-form-action-based-upon-a-variable/#findComment-513439 Share on other sites More sharing options...
laffin Posted April 9, 2008 Share Posted April 9, 2008 if u want it to be on the form itself, u can look at javascript validation. but dun rely on it, meaning keep a php validator in place. Link to comment https://forums.phpfreaks.com/topic/100398-two-different-form-action-based-upon-a-variable/#findComment-513446 Share on other sites More sharing options...
tcurtis Posted April 10, 2008 Share Posted April 10, 2008 Perhaps I missed something but couldn't you just run a switch in the one file so that based on the value of total you process the submited data in the same file but with two separate bits of code. Link to comment https://forums.phpfreaks.com/topic/100398-two-different-form-action-based-upon-a-variable/#findComment-513569 Share on other sites More sharing options...
poleposters Posted April 10, 2008 Share Posted April 10, 2008 if ($total>0) { print "<form action="checkoutA.php>" } else { print "<form action="checkoutB.php>" } Or something along those lines. Link to comment https://forums.phpfreaks.com/topic/100398-two-different-form-action-based-upon-a-variable/#findComment-513668 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.