Click here to Skip to main content
15,896,538 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I'm working for a tennisclubb and need to create a button on our page that sends the user to our booking system. The thing is that the URL ends with query string parameters, http://../../boka_reserve_reg_client_app.php?sess_adm_club_id=25&YEAR=2016&MONTH=04&DAY=26.

If I crop the URL right before the first "&" you will still be able to access the booking page but it will not have any function.

So what I need is a form that submits the parameters to the end of the URL where the user types the year, month and day or a pice of code that generates a new link every day with the correct date.

Is this possible to fix without using PHP? JavaScript is absolutely fine.

Thanks!

What I have tried:

I tried to link to the URL without the query string at the end.
Posted
Updated 26-Apr-16 7:36am
Comments
Sergey Alexandrovich Kryukov 26-Apr-16 13:38pm    
"What have you tried" means "what have you tried", not just mentioning that you tried something. You gave no idea on what you tried.
—SA

1 solution

The question, concerning your "without using PHP", makes no sense, it looks like.

If you use the query part in your URI to pass some data, you obviously do it to process this data on the server side. If it is PHP, you handle it with PHP. If you did not, you would not have these query parameters at all. Isn't that logical?

Therefore, in this approach, JavaScript is totally irrelevant, even if you actually use it, say, to calculate some URI strings and redirect the page using it. It doesn't matter what you do on the client side, it just matters what are the query parameters and how they are used. So, forget "without using PHP", unless you want to switch to some other server-side technology :-).

There are two obvious solutions:

First approach would be: modify server-side code to analyze the query string and accept any random query string, handling it accordingly. It will work, but this is ugly. It works only in certain cases, when you can clearly explain the user what is wrong. Say, if your page is a collection of jokes retrieved by a joke number passed as a query string parameter, you can say "Joke number #1000203230 does not exist yet" and show your "default joke" :-).
In more sensitive or complicated cases, it would be much better to get rid of this "low-tech" approach at all.

So, the second approach is to get rid of those query strings at all. This is actually a good idea. First of all, remember that even the query string parameters are not really indented for entering as text by the users (I do such things though, but this is not the developer's intentions). If such entering can be confusing or otherwise poorly functional, hide this information channel completely; it's not suitable. So, the user does not enter this data even in case of query strings; the string is formed as a result of some user's clicks in the page or other input events — on the page, not entering something in the address line.

All you need is to send data in HTTP request. For the user, the visible part of HTTP request is only the address line. Don't pass any parameters there, pass them in the body of the HTTP packed. Basically, in HTML it's done in one of two ways: a Web form or Ajax. I don't know if you can reasonably use the form; it depends on your HTML design, if not, you can always use Ajax. And this is where JavaScript comes into play.

Have you already forgotten the idea of not changing the server part? I'm sure you have, because you need to write proper server side to handle HTTP request from a form or Ajax. :-)

See, for example:
PHP and AJAX[^],
PHP: Dealing with Forms — Manual[^].

—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900