?
Solved

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

Posted on 2003-03-24
7
Medium Priority
?
167 Views
Last Modified: 2010-04-06
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
Comment
Question by:barrierobinson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 8199512
You can cange the action ans ubmit with JavaScript this way:

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

Cd&
0
 
LVL 33

Expert Comment

by:shalomc
ID: 8204198
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
 

Author Comment

by:barrierobinson
ID: 8204633
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
WordPress Tutorial 3: Plugins, Themes, and Widgets

The three most common changes you will make to your website involve the look (themes), the functionality (plugins), and modular elements (widgets).

In this article we will briefly define each again, and give you directions on how to install them.

 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 8205018
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
 

Author Comment

by:barrierobinson
ID: 8205276
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
 
LVL 53

Accepted Solution

by:
COBOLdinosaur earned 225 total points
ID: 8205746
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
 
LVL 19

Expert Comment

by:webwoman
ID: 8206058
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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
It's sometimes a bit tricky to use date functions in Oracle BPEL. I'll explain quickly how you can add N days to the current date. In a BPEL process this can be useful, and you can adapt it to fit your needs. First of all, let's see how to add 1 …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question