Reply to Re: Submit form with variable for action?

Your name:

Reply:


Posted by Chuck Anderson on 09/26/05 07:07

tencip wrote:

>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:
>
><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.
>
>
It's quite simple in JavaScript.

First, remove the action from the form definition
<form method="post" name="login" id="login" >

Then, instead of using type=submit, use type=button.
<input type=button name=submit value="Login"
Onclick="SubmitForm(this.form);">

function SubmitForm(form)
{
if (form.domain.value == "xxx")
form.action = "xxx"
else
form.action = "zzz";

form.submit(); // Submit the page
return true;
}

--
*****************************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
Integrity is obvious.
The lack of it is common.
*****************************

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация