Web Hosting Talk







View Full Version : Javascript form. Need desperate Help on my idea!


andreaf
09-13-2006, 01:21 PM
Hi there,
I want to have a form like this:

1) Only one text box and send button.
What you put on the textbox will be the name of the directory that will be opened when you click on "send".
I need this to send a user to his reserved area directory named as the user's username.
If the username is "california" the form should search for the folder "california" too when the user click on "send"
If the username is wrong it should send to an error page (404)
Hope it's pretty clear

2) This form should open the reserved area and enter into it with the username and password provided.
3 boxes (nameofthefolder, username, password)
I could also think of replicating the field "nameofthefolder" to appear also in the "username" field.

IS THIS POSSIBLE?
CAN ANYONE POINT ME TO THE RIGHT DIRECTION?

Please help this poor girl as my boss wants me to have this option for one of our clients pretty soon...

Andrea

maxymizer
09-13-2006, 02:05 PM
Folder that you're mentioning - it's on the server right? Also, in your description I see no room for javascript. If you're maintaning clients via javascript, someone can easily hack it and get access to other people's directories and that would happen sooner or later and I guess your boss wouldn't be too satisfied with that.

What you're looking for is a serverside solution (php / asp / perl / whatever you have available). You could use javascript for checking input without reloading the page (xmhlttprequest, also known as ajax), but to do the entire system in js - I suggest that you don't.

andreaf
09-14-2006, 02:45 AM
Maxymizer,
no problem to access all the other directories just because they are pwd protected.

The idea is to have the form to send guests to :

http://www.mysite.com/reserved/(username)

- In case someone enters a wrong username then it shows the 404 page
- In case someone enters a correct username it brings to the correct folder but a popup appears (asking username and password)

I'm not mantaining a database.
I've only one username and password for every protected folders.

I feel I need some kind of javascript form to achieve what my boss wants...

Thanks!

Andrea

Saeven
09-14-2006, 03:30 AM
Maxymizer is correct, you'll need to use AJAX and a backend to get this done the right way. JS is _not_ safe, it should only be used as a transport when authentication is at play.

Turn to dojo and the dojo.io.bind call. With a PHP proxy as backend, it wouldn't take any longer than 1 hour to implement or so.

ref: http://manual.dojotoolkit.org/io.html

andreaf
09-14-2006, 07:52 AM
Hi Saeven,
unfortunately I'm not an AJAX expert and the budget for this idea my boss gave me is 0!

I still don't think that what is on my mind is to hard to achieve with a javascript script...

Let me point out something more

Username and password are manually sent to customers (not even e-mail but postage mail notifications) and NOT generated by any kind of software.


We've 40 Folders and created one username and password to access each folder.

We don't want to let our web users the name of the 40 folders.

A guest must type the url www.mysite.com/name-of-the-folder
or add the username we provided in a text box click on "send" and the form must open the default site www.mysite.com/textaddedintheabovebox.

Is this possible?

Thanks guys!

Ryders
09-14-2006, 07:56 AM
Mmmmm.... I don't think Ajax is required to do this; you can quite easily hide information in the form post. Don't get me wrong, ajax would work, but far from being the only way!

Try something like this;

1. display the login.php page - if your post variable is not there, don't display a password field.

2. once the user hits submit (the form action should be index.php, to post itself), you simply verify if the folder exists and if it does, then display the password field, with the folder textbox being prepopulated, maybe read-only. if the folder name is different than the username, you'll also need a username textbox.

3. then the user enters a password and hits submit again. Then because you have a folder which exists and a password you simply redirect the user to that folder using a usual header('Location:...

up to now, you get the initial behavior you asked for... ;)


now because you don't want your user to type their password twice ( in that brower-generated login window thingy...! ), you have to make sure to add the username and password in the HTTP Request sent by the header(); check those two out; $_SERVER['PHP_AUTH_USER'] and $_SERVER['PHP_AUTH_PW'];

I'm pretty sure assigning those two before the header() would work, but I could be wrong - I've never done this so to speak. But my understanding of it says it should be all good!!

Let me know if you need more help, looking at the time of your post we're definately not in the same timezone, but if you can wait until I wake up... I'll be glad to help out! :P

This may be of interest as well... http://au2.php.net/features.http-auth

Cheers!

Seb.

typos.. typos.. typos... *sighs*!

andreaf
09-14-2006, 09:42 AM
Ryders and all the guys... Thanks for your support.

Unfortunately I've no skills at all on php.

I just believed that a simply form with the post

Please see the attachment.

Is it just possible to do that without any need of login pages?

Just remember that my basic need is to hit a "send" button and open a link (www.mysite.com) plus whatever has been written in the text box.

If I type "ILIKECARTOONS" and hit "send" the page will open the url www.mysite.com/ILIKECARTOONS (no matterif it exists or not).

Are you sure this is not possible with a javascript script?

I'm not a desperate housewife, I'm just desperate!

Andrea ;)

nnormal
09-14-2006, 12:21 PM
<form method="post" onsubmit="this.action=document.getElementById('me').value">
<input type="text" id="me">
<input type="submit" value=">">
<form>

jon31
09-14-2006, 12:45 PM
Yup, that should do it. Beat me to it. It should automatically go to a 404 if the username they entered doesn't exist.

andreaf
09-14-2006, 01:52 PM
YES, YES and once more... YES!

It works like a charm.

I feel that's enough I won't stress you anymore.

I'll try to search online a way to make the page to be opened in a pop-up or in a new page...

Thanks to you all!

Andrea

sasha
09-14-2006, 02:14 PM
I'll try to search online a way to make the page to be opened in a pop-up or in a new page...


Just add target="woosshhh" in the form tag and keep everything else the same.

<form target="woosshhh" .....

Ryders
09-14-2006, 03:57 PM
Just remember that my basic need is to hit a "send" button and open a link (www.mysite.com) plus whatever has been written in the text box.


Gee! much simpler than your original question ain't it!? Glad to see you figured it all!

Cheers!

andreaf
09-15-2006, 06:26 AM
It's so simple when you have such great people like you guys!

nnormal
09-15-2006, 10:33 AM
actually there's a syntax error in my snippet.
form element isn't closed properly...

:dunce: