• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 168
  • Last Modified:

posting form data to url via drop-down ...

I want to be able to post the data entered in a form to a specific location. The reason for this is that I have multiple member areas, that you can log-in to via a form. However I want to enable users to choose their member area and submit their username and password at the same time. This would be done like so:
http://server.com/Members/PersonalAccess/Martin/index.php?action=login&order=name&srt=yes
http://server.com/Members/PersonalAccess/Sarah/index.php?action=login&order=name&srt=yes
What I need to do is swop Martin for Sarah, or Bob or whatever via a drop-down selection. The data would be:
optional url's for data posting - drop down
username - text field
password -textfield
Is there some way of swapping the action value in <FORM name="login"  action="url?data" method="post"> ?
I hope somebody can help because I've just spent about five hours  looking around on the web and can't find anything on it. I've set up something before that enables htaccess via selected url but that's based on window location and not form submition.
Thanks
Barrie
0
barrierobinson
Asked:
barrierobinson
1 Solution
 
COBOLdinosaurCommented:
You can cange the action ans ubmit with JavaScript this way:

document.forms['forname'].action="url?data";
document.forms['formname'].submit();

Cd&
0
 
shalomcCTOCommented:
You can accept the user name as a form value, and redirect the user to the appropriate script based on the name, using a 301 HTTP response.
Sorry, can't tell you the exact PHP code.

0
 
barrierobinsonAuthor Commented:
COBOLd,

Something like... ? I can't seem to get this to work, however I am a bit of a novice at this. Design is really my skill.

Thanks

<!-- Begin
function Login(form) {
var username = form.username.value;
var password = form.password.value;
var server = form.server.value;
if (username && password && server) {

document.forms[login].action=server;
document.forms[login].submit();
}
else {
alert("Please ensure you have selected your user type \nand entered your username and password.");
   }
}
//  End -->

</script>


<form name="login">
<span class="trail">method<br></span>
<select name="server" class="emoform">
<option value="http://serverone/members/index.php?action=login&order=name&srt=yes"" selected>member
<option value="http://servertwo/clients/index.php?action=login&order=name&srt=yes">client
<option value="http://servertwo/suppliers/index.php?action=login&order=name&srt=yes">supplier

<input type=text name=username>
<input type=password name=password>
<input type=button value="go!" onClick="Login(this.form)" name="button">

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
COBOLdinosaurCommented:
I mad a couple of changes in your script.  I changed the name of the argument from and the variables, so the browser does not get confused.
The value for the server variable has to pick up the value of the selected option, the select itself does not hav a value.
I change the if statement.  The way you had it would always be true because it was just testing for the existence of the var.
I put quotes around login.  Without the quotes it would mean a variable named login but what is being referred to is the literal name of the element.

Try it that way and see if it does what you need
Cd&


<!-- Begin
function Login(theform) {
var uname = theform.username.value;
var pword = theform.password.value;
var theserver = theform.server.options[theform.selectedIndex].value;
if (uname!='' && pword!='') {

document.forms['login'].action=theserver;
document.forms['login'].submit();
}
else {
alert("Please ensure you have selected your user type \nand entered your username and password.");
}
}
// End -->

</script>


<form name="login">
<span class="trail">method<br></span>
<select name="server" class="emoform">
<option value="<http://serverone/members/index.php?action=login&order=name&srt=yes>"" selected>member
<option value="<http://servertwo/clients/index.php?action=login&order=name&srt=yes>">client
<option value="<http://servertwo/suppliers/index.php?action=login&order=name&srt=yes>">supplier

<input type=text name=username>
<input type=password name=password>
<input type=button value="go!" onClick="Login(this.form)" name="button">

0
 
barrierobinsonAuthor Commented:
sorry,

doesn't work. Having said that it didn't work before either.

1) what if form action="http://www.server.com/"

2) username input name=p_user

3) password input name=p_pass

4) select
the option value ="Members/Index.php?action=login&order=name&srt=yes"
or  option value ="Clients/Index.php?action=login&order=name&srt=yes"
or  option value ="Partners/Index.php?action=login&order=name&srt=yes"


What I basically need to do is:
post p_user and p_pass values to action + select value

Does this help, I appreciate the input. Thanks.


p.s. this works absolutley fine, I'm just looking to change the action value my providing a dropdown:

<FORM name="login" action="http://serverone/members/index.php? action=login&order=name&srt=yes" method="post">
<INPUT name="p_user" type="text" size="20" class="usersmallfield">
<INPUT name="p_pass" type="password" size="20" class="usersmallfield">
<INPUT type="submit" value="Login">

0
 
COBOLdinosaurCommented:
okay I see the problem the form already has an argument string.  You are trying to add to it. and that is what is breaking it.

the form is already sending p_user and p_pass and the selected option as the post argument string.

You can change the action by appending the rest of the page address, but not the arguments. You either have to
Either have to move the arguments in the select argument to hidden fields so they submit as part of thr form argument string,  or you need to make build the whole url and cgange the href of the page. The second way will put the password in the open unlike the post  method of a form.

Cd&
 
0
 
webwomanCommented:
I question why you're going about it this way. It's unnecessarily complex.

Why not ONE login page, and from that you direct them to the appropriate location. You're going to have multiple pages, which is going to be a maintenance NIGHTMARE. A completely unnecessary one, IMHO.

You DO have their area of access stored in the database along with their username/password, right? If not, you should.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now