Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: How to save search criteria for use beyond a form action

  1. #1
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    642
    Thanks
    284
    Thanked 15 Times in 15 Posts

    Default How to save search criteria for use beyond a form action

    I have just created a custom search form (first form) for a table that holds 35K clients. The search works fine. The result page lists the clients that match the search criteria. If you click on a client, a pop-up window lets you edit the client info (second form) and then save the changes.

    The problem is that when you click Save Changes on the second form the window closes and returns you to the search results page, but the search criteria are gone so it tries to list all 35k clients and hangs the browser. Not sure how to save the value of the search query variable. I have tried everything I can think of and finally had to disable the pop-up window.

    Here is the last thing I tried, but the value for $page gets lost by the time it gets to this file... the ideal result would be for the search results page to show with the filtered list that was there before the pop-up edit window, but at this point I'll settle for going back to the search page. But even that doesn't work! Please help. Mahalo, e

    Code:
    if($page == 'search-clients'){
      header('Location: /admin/php/search-clients.php');
    } else {
    // Refresh Client Listing
    $header2 ="<SCRIPT LANGUAGE='JavaScript'>\n";
    $header2.="<!-- Begin\n";
    $header2.="page = opener.document.URL;\n";
    $header2.="opener.document.location = page;\n";
    $header2.="window.close();\n";
    $header2.="//  End -->\n";
    $header2.="</script>\n";
    echo $header2;
    }
    exit;  
    ?>

  2. #2
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    you could use a hidden variable to pass the search criteria that was used to the next page.

    <input type="hidden" value="<?php print $search_criteria;?>" name="search">

    State that $search_criteria will only be retrieved if changes have been made.

    This does use a bit of javascript though, so take my answer with a grain of salt.
    To choose the lesser of two evils is still to choose evil. My personal site

  3. #3
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    642
    Thanks
    284
    Thanked 15 Times in 15 Posts

    Default

    Dear james: Thanks for the advice but I'm not sure where to put the hidden variable and have no clue how to state that it will be retrieved only if changes are made. I am pretty brain dead when it comes to javascript. Can you please be more explicit?

    Thanks, e

  4. #4
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    Well, if I understood javascript I might be able to give you exactly what you need, but I think I can still help you a little. Take a look at the following:

    Code:
    <?php
    $search_criteria=$_POST['search_criteria'];
    $page="$search_criteria";
    if($page == 'search-clients'){
      header('Location: test.txt');
    } else {
    // Refresh Client Listing
    $header2 ="<SCRIPT LANGUAGE='JavaScript'>
    <!-- Begin
    page = opener.document.URL;
    opener.document.location = page;
    window.close();
    //  End -->
    </script>";
    echo $header2;
    }
    ?>
    <form action="<?php print $_SERVER['PHP_SELF']; ?>" method="post" name="search">
    <input type="text" name="search_criteria"    value="<?php print $search_criteria;?>">
    <input type="submit" name="newbutton" value="Submit Form">
    </form>
    This is a simple script where you can type in any text and the text will be passed to the next page, which in this case is itself. $_SERVER['PHP_SELF']; is merely the location of the page that you are viewing. You can pass variables from one page to the next using one or both of two primary methods: $_GET['']; and $_POST['']; In this example we are creating a form that passes values using the POST method. input type="text" says that you can type in the values in a text field. name="search_criteria" is the name of the value. The value itself if presented as value="text" or whatever value you want.

    <input type="submit" is one of about a dozen different submit types you can use and is used to create a button that will tell the browser to go to the next page. The button in this case has the name of "Submit Form".

    To retrieve the value, hidden or not, use $search_criteria=$_POST['search_criteria'];

    Now the value from the previous page is stored in the variable $search_criteria; If you have a big script and have trouble remembering all of the values that you have passed to the next page use: print_r($_POST); You can also use <pre><?php print_r($_POST); ?></pre> to view them in an easier to read format.

    I formatted your $header variable above into a format that was easier for me to read, but it should still operate the same. Dunno what it does though. For the purposes of this page it is not necessary at all.

    When you type in any ol' text into the text field it will be passed to the next page unless it is equal to "search-criteria" where it will then go to a different page. Basically if $search_criteria != ""; the value is passed to the next page. It is only when the value has the special value of "search-criteria" that it will perform a special action.
    To choose the lesser of two evils is still to choose evil. My personal site

  5. The Following User Says Thank You to james438 For This Useful Post:

    kuau (09-21-2010)

  6. #5
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    642
    Thanks
    284
    Thanked 15 Times in 15 Posts

    Default

    Thanks James. I am still having trouble following this. The javascript was from some old code I inherited which worked to reload a page after a pop-up window closed so I used it here to try to do the same thing, but I'm not 100% sure about what it does either. That could be one problem.

    I may have complicated this by inserting my desperate Plan B attempt to get it to stop loading the whole table. I really just want it to keep the page on the screen that is under the pop-up window, but because that didn't work, I tried to load the page 2 pages back. When the pop-up window (second form) closes, it updates the client table with any changes made to the client record in the pop-up window.

    The code I provided was from the php action page of the second form (pop-up window). There is no web-facing html in this script that updates the client table. If I add a submit button to this script, who is going to click on it? Sorry, maybe I need to wake up more before I read this. I'm hoping this now makes more sense to you so it may rub off on me.

  7. #6
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    You are probably looking more for javascript help with some of your questions, which I never really got a handle on. As far as who would click on the button it is set to work for anyone right now, but you could use cookies or sessions so that only those who are logged in to your site can use the button.

    just a thought.

    True, there is no MySQL code to update your table. I figure you probably already have that and are familiar with what you want to do. If you want we can insert some into the script.

    While I am unable to create a javascript that will create a popup balloon where you can edit one client I can suggest a php script where you have a search form where you enter the search criteria as in the example I posted above. You will then be taken to another page which lists all of the returned results in a hyperlinked format so that when you click on a particular client you will be taken to a page where you can edit the data and hit the submit button. Afterwards the screen will display the old client info side by side with the new client info.

    That's probably not what you are looking for though.
    To choose the lesser of two evils is still to choose evil. My personal site

  8. #7
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    642
    Thanks
    284
    Thanked 15 Times in 15 Posts

    Default

    I already have all that code written and working no problem (ie. the pop-up window, the edit form, the database table update). Everything is working perfectly except the one issue of it loading the entire table after closing the pop-up window.

    I guess I haven't explained this properly. Sorry to have made it so confusing. Maybe I'll ask in the javascript forum. I suspect it is only one line of js code I need.

    I would be interested in seeing the php script you're talking about so I can compare it to the one I did. I'm sure it's probably better than mine. Thanks very much for trying to help me.

  9. #8
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    no, I'm pretty sure that I understand, but I also know that I am unable to help you with exactly what you are trying to do which is why I was attempting to create a php work around solution since that is what I know. You definitely need to post this in the javascript forum where the javascript experts can tackle this.

    Sorry I was not able to be of much help in this case.

    Good luck!
    To choose the lesser of two evils is still to choose evil. My personal site

  10. The Following User Says Thank You to james438 For This Useful Post:

    kuau (09-21-2010)

  11. #9
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    642
    Thanks
    284
    Thanked 15 Times in 15 Posts

    Default

    OK, thanks!

  12. #10
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    642
    Thanks
    284
    Thanked 15 Times in 15 Posts

    Default

    Dear James: No one in the js forum even responded. I just wanted to let you know that I figured out how to stop the whole table from loading. When the pop-up window closes, it shows the Search Results page but with only a link to take you back to the search page. It's not what I was hoping for but at least it doesn't hang the browser.

    I did it by putting an if(isset($search_criteria)){ around the search results code and then if the variable is not set, it does this...

    Code:
    echo '<p>Please click to <a href="javascript:history.go(-1)">Return to Seach Page</a></p>';
    I tried using header('Location: ../php/search-clients.php'); but got an error message about the headers already being set. Not sure what it wants instead. I settled for a link on the results page that takes you back to the search page. I wouldn't have thought this would be so difficult.

    Anyway, I appreciate your efforts to help me. Hope I can help you sometime. Hey, today's my birthday!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •