Connecting Tech Pros Worldwide Help | Site Map

Form processing: change the "action=" based on pull down menu

Sylvie Stone
Guest
 
Posts: n/a
#1: Jul 17 '05
Hi group -

I have an html form for that uses username and password to login to a
specific area of the website. The "area" the user wants to go to is
based on a pull down menu. Becasue the user/password info is in
differnet databases, how can I call different validation scripts based
on this input ?
THANK YOU!

See below please. Somethinglike this:

form.html:
<form name="loginform" method="post" action="login.php">
<select name="loginform">
<option value="one">Section 1</option>
<option value="two">Section 2</option>
</select>

login.php:

@extract($_POST);
if($_POST[loginform] == "one") {

echo "action = /forums/scc/dispatch.cgi/_admin/AVFLogin"
NAME="LoginForm" >
echo "<input type=hidden name=\"autologin\" value=\"1\">\n";
echo "<input type=hidden name=\"formstyle\" value=\"standard\">\n";
echo "<input type=hidden name=\"returnforum\" value=\"_admin\">\n";
echo "<input type=hidden name=\"returnmsg\"
value=\"acahomepage\">\n";

} else {

echo "action = /path to different cgi \n";
echo :different values for hidden fields".

}
Erwin Moller
Guest
 
Posts: n/a
#2: Jul 17 '05

re: Form processing: change the "action=" based on pull down menu


Sylvie Stone wrote:
[color=blue]
> Hi group -
>
> I have an html form for that uses username and password to login to a
> specific area of the website. The "area" the user wants to go to is
> based on a pull down menu. Becasue the user/password info is in
> differnet databases, how can I call different validation scripts based
> on this input ?
> THANK YOU![/color]

Hi,

This is actually a javascript trick you need.
You can dynamically set the action of a form, just by assigning a new value
to it.

Try something like this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<html>
<head>
<title>formactiontest</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="Quanta Plus">

<script language="javascript">

function doSubmit(){
// get the chosen option
selind = document.forms.mydynamicform.selectaction.selected Index;
// get the value
selval = document.forms.mydynamicform.selectaction[selind].value;

// now set this value as action for the form
document.forms.mydynamicform.action=selval;

// and submit
document.forms.mydynamicform.submit();

}

</script>

</head>
<body>

<form action="unknownyet" METHOD="POST" name="mydynamicform">

Choose your action:
<select name="selectaction">
<option value="login1.php">go to login 1</option>
<option value="login2.php">go to login 2</option>
<option value="login3.php">go to login 3</option>
</select>
<br>
Your name? <input type="text" name="yourname" size=10>
<br>
<input type="button" onClick="doSubmit()" value="Go!">

</form>

</body>
</html>


Regards,
Erwin
Sylvie Stone
Guest
 
Posts: n/a
#3: Jul 17 '05

re: Form processing: change the "action=" based on pull down menu


sylviestone@canada.com (Sylvie Stone) wrote in message news:<181a24a8.0309160650.45b744df@posting.google. com>...[color=blue]
> Hi group -
>
> I have an html form for that uses username and password to login to a
> specific area of the website. The "area" the user wants to go to is
> based on a pull down menu. Becasue the user/password info is in
> differnet databases, how can I call different validation scripts based
> on this input ?
> THANK YOU![/color]


THANKS A LOT to Erwin and NC for posting two excellent solutions.
i have taken bits from each and implemented the code and it's working very well.

Thanks again,

Syl.
Closed Thread