Page 1 of 1

Form submission with dynamic action

Posted: Sun Sep 25, 2005 3:07 pm
by cozimek
Hi everyone,

So, i've got a form that is very simple. It hold three elements:
username, password, and domain. The goal here is to have the form
submit the login to an administrative section depending on which domain
someone has chosen.

For instance, let's say we have three administrative sites, that all
have different URLs, but we want this one form to handle logging into
any of them. So, the form itself needs to have a dynamic action
element.

Here's an example:

Code: Select all

<form action="http://www.mysite.com/admin/index.php" method="post"
name="login" id="login" >
        <input name="usrname" type="text">
        <input name="pass" type="password">
        <input name="domain" type="text">
        <input name="submit" type="submit" value="Login">
</form>
Now, the issue is, instead of the action I have now, I need the action
to change based on what is typed by the user in the domain field. So in
the case above, if the user types "bobsite.com" in the domain field,
the action needs to point to "http://www.bobsite.com/admin/index.php".

I have looked near and far for a solution for this. Using PHP, so have
some flexibility, and javascript is okay if we have to use it.

Posted: Sun Sep 25, 2005 3:16 pm
by shiznatix
use switch case

Code: Select all

switch "$_POST['domain']"
{
  case "bobs.com":
    header ("location: bobs.com/admin/index.php");
  case "steves.com":
    header ("location: steves.com/admin/index.php");
}
if you need the login information to go with that then use $_GET, put the username and password, hased of course, along with the header.