PassMark Logo
Home » Forum

Announcement

Collapse
No announcement yet.

how to populate search box automatically

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • how to populate search box automatically

    I have a requirement on a web page to populate the Zoom search box with a php variable called $term so that this expression appears in the zoom search box and when the user clicks on submit will search for that term.
    This is an alternative to manually typing in search parameters but have not so far managed to achieve this or find other posts relating to this.
    Using standard edition registered version.

  • #2
    Pre-populating the search box has been discussed:
    Input text in search box pre-search

    One would typically do this with Javascript. So you can have some PHP which writes out the JS to populate the box.

    Or you can just manually write out your own search box with the HTML as specified here:
    Q. How do I put search forms on pages besides the search page? (Or define my own search form?)
    --Ray
    Wrensoft Web Software
    Sydney, Australia
    Zoom Search Engine

    Comment


    • #3
      With the expression:
      <input type="text" name="zoom_query" size="10" value="Your text here">
      What I need to do is somehow replace "Your text here" with a variable which I have generated by:

      $_POST['$term'];
      $zoom_query = $_POST['term'];
      ?>

      I have checked that the above lines do work as they create the expression I want for searching.
      However what I am trying to do is put the term $zoom_query in place of manually typed text then be able to send it to the zoom search engine.

      Comment


      • #4
        As I mentioned, you can have your PHP write out your own HTML search form, with whatever values you want pre-filled in. There's a FAQ linked above that gives you the HTML. You can disable Zoom from generating a search form so you don't end up with two forms on the page.

        OR you can use JS to pre-populate the form with your desired value, without clearing it when the user clicks on it, by adapting the code in that forum thread I first linked to.

        OR what you are suggesting would involve hacking the "search.php" script somewhere in the middle so that it takes a search term, but doesn't perform a search on it, and only use it to populate the form (which is normally populated with what the user just searched for). That's possible, sure. But you should need to be pretty familiar with PHP to do so because:
        (1) We do not provide support for modified scripts. We can't. It'd mean we'll spend all our time debugging other people's code than our own.
        (2) There'll be extra work for you when ever new builds are released (for bug fixes, etc.) and you need to port your code changes over each time. And it won't be the same line number each time because the code will change so you need to understand it well.

        If that's what you really want to do, by all means, but as I noted, there are alternatives that seem more appropriate.
        --Ray
        Wrensoft Web Software
        Sydney, Australia
        Zoom Search Engine

        Comment


        • #5
          Using the example in the "Input text in search box pre-search" faq/stream quoted I end up with "Your text" in the text box.
          What I shall try and achieve is replacing the words "Your text" with a php string. Not been successful so far, though I have the term I want just two lines above :
          $_POST['$term'];
          $zoom_query = $_POST['term'];
          ?>

          It is doubtless easy enough, but these sort of issues can take ages to resolve.
          The JS second option may be the next thing to look at.

          Comment


          • #6
            You need to realize that PHP is server-side scripting and Javascript is client-side scripting. So it means your PHP can write the JS code for the browser to execute. Which means it can write out that JS code, and replace "Your text" with any PHP variable.

            Or you just specify the HTML if you only want it to be populated (and not respond via clicking or un-selecting), in other words, something like:

            print('<input type="text" name="zoom_query" size="10" value="'.$_POST['term'].'" />');

            If these are foreign concepts to you, I would suggest finding a PHP/JS programmer to write PHP/JS code.

            I can't give you line-by-line code to copy and paste in, without knowing the context of the pages in question, and for the reasons explained in my last post.
            --Ray
            Wrensoft Web Software
            Sydney, Australia
            Zoom Search Engine

            Comment


            • #7
              fixed

              Ray, thanks and I'm okay with php, javascript and html limitations, but getting the right syntax, expressions and formatting can be quite a challenge!

              Problem now solved thanks to your suggestion:
              <form method="get" name="zoom_query" action="zoom/search.php" />
              <?
              print('<input type="text" name="zoom_query" size="16" value="'.$_POST['term'].'" />');
              ?>
              <input type="submit" value="Search" />

              I am working on a web site refresh and this was one of the features I needed.
              Onwards and Upwards! http://www.wrensoft.com/forum/images/icons/icon7.gif

              Comment

              Working...
              X