Form action variable?

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

Post Reply
dissonantallure
Forum Newbie
Posts: 21
Joined: Tue Feb 03, 2009 7:48 pm

Form action variable?

Post by dissonantallure »

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?
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: Form action variable?

Post by flying_circus »

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>
Post Reply