...

View Full Version : Add Values to URL



byrondallas
12-02-2012, 10:55 PM
Hi guys! I'm pretty much lost when it comes to javascript and I'm hoping somebody can help me. What I have is a form that when the "Do URL" button is clicked, it drops the url into the text field. But now I want to be able to add values to the url when the "Do URL" is clicked. This is what the url would look like:


http://yoohoo.com/login_whatever.php?username=USERNAME&password=PASSWORD

Where you see the uppercase username and password is where I want to add the values from the login fields. Here's the code I'm using now for the form:

http://area52.heliohost.org/misc/url_form.html

Thanks for any help.

Old Pedant
12-03-2012, 06:43 AM
Making it way way way too hard.

No JavaScript needed, at all.

Boiled down to the bare essentials:


<form method="get" action="http://yoohoo.com/login_whatever.php">
<input type="text" name="u" size="25">
<input type="text" name="username">
<input type="text" name="password">
<input type="submit" value="Go">
</form>

I don't know what the purpose of your name="u" field is, but it *TOO* will be send along to login_whatever.php as part of the URL.

If you don't need/want it, then omit it.

byrondallas
12-03-2012, 08:11 AM
I wish it were that simple, but I really need the javascript to place the username and password inside the url. I fully understand what your saying, but that won't work for this particular application.


I don't know what the purpose of your name="u" field is, but it *TOO* will be send along to login_whatever.php as part of the URL.

It has to do with this function (not written by me btw):


function doIt(v_al)
{
var t_a1 = document.forms["theform"].elements["u"];
if (t_a1.value.indexOf(v_al) == -1)
{
t_a1.value += v_al;
}
}


When you click the Do Url button, it loads the url inside this url textfield:


<input type="text" name="u" size="25">

So what I need to happen is when the person enters the username and password and clicks Do Url, the url gets loaded into the url textfield with the username and password in the url. So that the url would look like this in the url field:


http://yoohoo.com/login_whatever.php?username=USERNAME&password=PASSWORD

Of course where you see the uppercase USERNAME and PASSWORD, that's where I need the javascript to pass the username and password values from the login form.

Old Pedant
12-03-2012, 08:38 PM
So you aren't showing us real code?

Because *clearly* this <form> is useless:


<form action="" method="post" name="theform">

It posts back *TO THE SAME PAGE* and it uses method="post", which means that even if we do all that you ask, you will end up sending the following POST data back to this same page:


http://localhost/dearabby/junk1.html?u=http%3A%2F%2Fyoohoo.com%2Flogin_whatever.php%3Fusername%3Dasdfa+asdf%26password%3DNAX23 4&submited=Go&username=asdfa+asdf&password=NAX234

Which is (a) illegal because an HTML page can't receive POSTed data and (b) incredibly redundant, because you will be sending the username and password info *TWICE*.

SO... It would help if you would use *REAL* code instead of giving us fake code that is somewhat meaningless.

I would *GUESS* that what you are really after is *SOMETHING* like this:


<html>
<head>
<title>Untitled Document</title>
<script type="text/javascript">
function doIt(btn, url)
{
var form1 = btn.form;
url += "?username=" + form1.username.value;
url += "&password=" + form1.password.value;
var form2 = document.getElementById("theRealForm");
form2.u.value = url;
form2.submitted.focus();
}
</script>
</head>
<body>
<br><br>
<br><br>
<table align="center" border="0" cellspacing="10">
<tr>
<td align="center" colspan="2">
<form action="somepage.php" method="post" id="theRealForm">
<input type="text" name="u" size="25">
<input type="submit" name="submited" value="Go">
</form>
</td>
</tr>
<form id="dummyForm">
<tr>
<td align="right">Username:</td><td><input type="text" name="username">
</td>
</tr>
<tr>
<td align="right">Password:</td><td><input type="text" name="password">
</td>
</tr>
<tr>
<td align="center" colspan="2">
<input type="button" name="theform" value="Do URL"
onclick="doIt(this,'http://yoohoo.com/login_whatever.php');">
</form>
</td>
</tr>
</table>
</body>
</html>

Though presumably with all sorts of other stuff you didn't show us.

No?

felgall
12-03-2012, 08:47 PM
Whatever values you set in the form from JavaScript will need to be redone on the server after the form is submitted for those people without JavaScript so you should get that version working first and then decide if there will be sufficient time saving for those with javaScript if you implement something in JavaScript.

byrondallas
12-03-2012, 11:23 PM
So you aren't showing us real code?
SO... It would help if you would use *REAL* code instead of giving us fake code that is somewhat meaningless.


I'm showing you the code I'm using, just not the end result. I guess I should explain and maybe it will help shed some light on what's going on. The doIt function is on a proxy. All it does is drop the url into the url form and then you click the proxy submit button to submit the url. This is being used by people who are on a really old browser called webtv and they can't handle secure communications without going through a proxy. The site they want to go to is fastmail.fm, but just going to fastmail.fm through the proxy by entering this url https://fastmail.fm fails for them because fastmail is using this as the form action <form action="/">. Every time they submit the login info through the proxy, it just takes them back to the proxy home page instead of there mail page. The doIt function was already on the proxy page and it just dropped in the fastmail url into the proxy form but like I explained previously, fastmail has changed thier form action. So after some testing I found a way for them to get back to thier fastmail email by entering this into the proxy form:


https://www.fastmail.fm/?dologin=1&page=m.html&interface=html&screenSize=mobile&hasPushState=0&username=USERNAME&password=PASSWORD

So what it all boils down to is that I want the users to be able to enter thier username and password and click doIt and the url (above) get's entered into the proxy form with thier username and password in the url. Then they click submit and the proxy takes care of the secure communications for them.

LOL it wasn't that I was hiding anything, it was just to much to have to explain.



I would *GUESS* that what you are really after is *SOMETHING* like this:


YES! That's exactly what I'm after. Thank you so much for your help!

Old Pedant
12-03-2012, 11:49 PM
Sorry, I didn't mean you were trying to conceal stuff from us, just that there was no way the code, as you showed it, could work.

It still can't work as you showed it, if the page you showed us really is an HTML page, for the reasons I gave you.

But hopefully now you can use some of what I showed to make it work?

byrondallas
12-03-2012, 11:57 PM
The proxy is a php page. The page I posted was just an example of what's on the proxy page. I really didn't want to post the proxy nor would you have been able to view it unless I changed the htaccess to allow more than webtv people. Anyway the code you posted works perfect for my application! :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum