will35010 Posted August 26, 2010 Share Posted August 26, 2010 I have a simple form: <form name="form1" method="post" action="login.php"> <p> <label>Username: <input type="text" name="username"> </label> </p> <p><label>Password: <input type="password" name="password"> </label></p> <p><label>Organization Code: <input type="text" name="organization"> </label></p> <p><font size="2" face="Verdana"> <input type="submit" name="submit" id="submit" value="Login"> <br> </font> </span></p> </form> What I want to do is change the action of the form based on the input of organization. Example: if($_POST['organization'] == 'test'){ action="../application/test/display/login.php" } How would I do this where it works? Thanks! Quote Link to comment Share on other sites More sharing options...
fortnox007 Posted August 26, 2010 Share Posted August 26, 2010 Heya I would loved to know that too, because exactly like you want it isn't possible it think because the form can't be conditional as far as i know with just php and html. (please correct me if i am wrong, i still have alot to learn) But what you could do is have a page where people only select company_ code and than press submit. when the page reloads the value of company_code is checked and leading him to the right if statement. Ill post a code in a few minutes ; ) Quote Link to comment Share on other sites More sharing options...
will35010 Posted August 26, 2010 Author Share Posted August 26, 2010 Heya I would loved to know that too, because exactly like you want it isn't possible it think because the form can't be conditional as far as i know with just php and html. (please correct me if i am wrong, i still have alot to learn) But what you could do is have a page where people only select company_ code and than press submit. when the page reloads the value of company_code is checked and leading him to the right if statement. Ill post a code in a few minutes ; ) That's how I've been doing it is with a form that ask organization first and uses header to redirect to login for selected. I'll guess I'll keep it the same for now. Quote Link to comment Share on other sites More sharing options...
fortnox007 Posted August 26, 2010 Share Posted August 26, 2010 This is what managed to put together for you. Had some beers so it might not be as efficient as it should be. But it works. I would love to see your script btw, maybe i can learn from it ; ) But i really would love to see if some phpfreaks guru thought us how to do this the best way <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <!-- copyright fat monkeys eat banana's --> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <title>conditional form-action</title> </head> <body> <?php if(!isset($_POST['submit'])){ if($_POST['organization']!==''){// if organization is not empty echo '<form method="post" action="/test/conditionalformaction.php">'; echo '<label for="username">Organization:</label>'; echo '<input type="text" name="organization" />'; echo '<input type="submit" name="companysubmit" id="submit" value="Confirm Company" />'; echo '</form>'; }else{ echo 'you need to provide a company name'; echo '<form method="post" action="/test/conditionalformaction.php">'; echo '<label for="username">Organization:</label>'; echo '<input type="text" name="organization" />'; echo '<input type="submit" name="companysubmit" id="submit" value="Confirm Company" />'; echo '</form>'; } } // this is a conditional form if(isset($_POST['companysubmit'])){ if ($_POST['organization']!==''){ echo '<form method="post" action="/test/'.$organization.'.php'">'; //you can ofc also make an array with action stuff echo '<h3>Company: '.$_POST['organization'].'</h3>'; echo '<label for="username">Username:</label>'; echo ' <input type="text" name="username" /><br />'; echo '<label for="password">Password:</label>'; echo ' <input type="password" name="password" /><br />'; echo '<input type="hidden" name="organization" value="'.$_POST['organization'].'"/>'; echo '<input type="submit" name="submit" id="submit" value="Login" />'; echo '</form>'; } } if(isset($_POST['submit'])){ if($_POST['username']==''&& $_POST['password']=='') {echo 'You need to provide a valid username and password combination';} } ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.