Form submission with dynamic action

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
cozimek
Forum Newbie
Posts: 1
Joined: Sun Sep 25, 2005 2:32 pm

Form submission with dynamic action

Post 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.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

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