I am at that stage of creating a web-site where I need to figure out how to have a user input 2 dates at any page and upon pressing "Find" go the the booking page where name, email etc. will be asked for. However, instead of filling out the dates again, I need them to be fillied out from the dates chosen on the previous page, that is to parse the form's inputs from page one to page two. Now, I have read that it could be done with JavaScript using cookies and by using PHP.
My question is: what is considered a better practice and why? And if there are other good ways, what are they and why are they considered good?
From what I understand, JavaScript is heavier to process, but is a good solution if php is not available to the web-site developer. Also, JavaScript is subject to being enabled on one's computer.
PHP, on the other hand is a more orthodox way, yet requires a database, so that with each submission, more and more entries in the database would apper, so more memory requires to host it.
Please correct me if I am wrong, especially about the PHP method.
You make a couple of incorrect assumptions, so let me try to answer your question.
First of all you have to realize that JavaScript and PHP are conceptually totally different languages. JavaScript runs on the user's computer, while PHP runs on the server. JavaScript is a client-side language, while PHP is a server-side language. Take a look at this answer for a detailed explanation about the difference.
Generally speaking, you should use JavaScript to make web pages dynamic and use a server-side language like PHP for the business logic. In your case PHP would be the way to go.
The drawbacks you mentions for PHP are not true. You can use PHP with a database, but it is by no means mandatory. In your case there's no reason not to use it.
What you should do to create the webpage you mention is the following:
Make a form where the user can enter the dates and set its action to the second page;
Read this form on the second page using a server-side language (in PHP: $_POST['date']
) and use it to fill out the form.
That should do the trick.
You need all completed steps before saving to database (read: handling by back-end), so it's better to handle the steps and their navigation client side. If all steps completed, post full form to back-end.
The most simple approach is this:
Pseudo code below:
<form name="myForm" action="yourbackendlink" method="post">
<div id="step1">
// your first form here
<input type="button" value="Next">
</div>
<div id="step2">
// your next step here
<input type="submit" value="Finish">
</div>
</form>
De first button:
De finish button: