Page 1 of 1

Form action variable?

Posted: Thu Mar 25, 2010 3:17 am
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?

Re: Form action variable?

Posted: Thu Mar 25, 2010 12:07 pm
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>