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!
Moderator: General Moderators
dissonantallure
Forum Newbie
Posts: 21 Joined: Tue Feb 03, 2009 7:48 pm
Post
by dissonantallure » Thu Mar 25, 2010 3:17 am
Hello,
I have a form and I would like to set a variable for the action depending on users input. For instance;
Code: Select all
<?php
if($_POST['first'] == '2')
{
$formaction = 'session2.php';
} else if($_POST['first'] == '3'){
$formaction = 'session3.php';
} else if($_POST['first'] == ''){
$formaction = 'session.php';
}
?>
<form action="<?php if(isset($_POST['first'])) echo $formaction; ?>" method="post">
<label>First Name:<input type="text" name="first" /></label>
<label>Last Name:<input type="text" name="last" /></label>
<input type="submit" name="poneSubmit" value="Continue" />
</form>
Can anyone please help me along in the right direction?
flying_circus
Forum Regular
Posts: 732 Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR
Post
by flying_circus » Thu Mar 25, 2010 12:07 pm
What is your code not doing that you want it to?
Code: Select all
<?php
$formaction = 'session.php';
if(isset($_POST['first'])) {
if($_POST['first'] == '2')
$formaction = 'session2.php';
if($_POST['first'] == '3')
$formaction = 'session3.php';
}
?>
<form action="<?php echo $formaction; ?>" method="post">
<label>First Name:<input type="text" name="first" /></label>
<label>Last Name:<input type="text" name="last" /></label>
<input type="submit" name="poneSubmit" value="Continue" />
</form>