Back previous page and save search conditions

I have an index.html page, where is an html form with some fields, for example AUTHOR and TITLE. These fields are created dinamically as DOM objects. The user type datas into the form and click submit. Then index.html POST the datas to search.php. This php site searches in mysql database and writes the search results into an html table on the search.php. I added an BACK button on the search.php. When the user clicks on the BACK button, this buton goes back to the index.html. I want to the user can see the search datas in the fields.

For example user types into the authors field: Paulo Coelho and the title field: The Alchemist. Then hits SUBMIT button and search.php searches in the database and writes out the results. After user want to back to the prevous page and hits BACK button. This goes back to index.html and here the AUTHOR field is filled with Paulo Coelho and TITLE is filled with The Alchemist. I would like to get any solution for this problem. I have already some starting points, for example php session, cookies, or POST back search conditions to index.html. Thanks!

Answers


Have you tried window.history.back() any values typed in the input boxes will be preserved:

<input type="button" value="Back" onclick="javascript:window.history.back();" />

First of all change the index.html to index.php so you can use php code there, Than store the form values in the session and then echo the session values.

First on all start the session of both the pages..

<?php session_start(); ?>

Store the Posted values in session like this.

<?php 
           $_SESSION['fieldvalue1'] = $_POST['fieldvalue1'];
           $_SESSION['fieldvalue2'] = $_POST['fieldvalue2'];    
?>

And then echo to values in form like

 <input type="text" value="<?php 
    if(isset($_SESSION['fieldvalue2']))
    {
        echo $_SESSION['fieldvalue2']
    }
    unset($_SESSION['fieldvalue2'])
    ?>" name = "fieldvalue2">

Need Your Help

@media query looks OK but doesn't work

html css ipad

Did a simple test of @media queries to see what works:

std::thread with movable, non-copyable argument

c++ multithreading c++11 rvalue-reference

The following program doesn't build in VS11 beta, gcc 4.5, or clang 3.1