Jump to content

how to complete search form?


bwakad
 Share

Recommended Posts

Does anyone have an example of how to complete a search form??? I took some part from the skyscrapers for the form, and it's populating the fields good. But the whole idea behind skyscrapers is a bit to complicated with the functions and renders.

How to send to search and complete an output???

I could not find any example and this for me is the first time creating a search...

Search_form.php:

<form id='my_search' method='get' action='<?php echo $config->urls->root?>search/'>
    <p>
    <label for='search_branche'>Branche</label>
      <select id='search_branche' name='branche'>
        <option value=''>Any</option><?php
        // generate the Branche options, checking the whitelist to see if any are already selected
          foreach($pages->get("/branche/")->children() as $branche) {
               $selected = $branche->name == $input->whitelist->branche ? " selected='selected' " : '';
               echo "<option$selected value='{$branche->name}'>{$branche->title}</option>";
          }
        ?>
      </select>
    </p>
    <p><input type='submit' id='search_submit' name='submit' value='Search' /></p>
</form>

search.php

$selector = '';

// we use this to store the info that generates the summary of what was searched for
// the summary will appear above the search results
$summary = array(
    "branche" => ""
// will need to expand these later on
    );

// if a branche is specified, then we limit the results to having that branche 
// (branches field in those pages)
if($input->get->branche) {
    $branche = $pages->get("/branche/" . $sanitizer->pageName($input->get->branche));
    if($branche->id) {
        $selector .= "branche=$branche, ";//CHANGE YOUR SELECTOR AS SHOWN HERE
//    $summary["branche"] = $branche->title;
    $input->whitelist('branche', $branche->name);
    }
}

// here's where it get complicated - at bottom it says:
$content = renderSkyscraperList(findSkyscrapers($selector));
Link to comment
Share on other sites

So, I added one piece of code from 'branche', but the only part getting accepted is from the original keywords input box.

Again, how can one expand/modify if there are non examples?

This is the search form in head.inc:


                        <form id="search_form" action="<?php echo $config->urls->root?>search/" method="get">
                            <div class="row collapse">
                                <div class="small-9 columns">        
                                    <input type="text" placeholder="Keywords" name="q" id="search_query" value="<?php echo htmlentities($input->whitelist('q'), ENT_QUOTES, 'UTF-8'); ?>" />
                                </div>
                                <div class="small-3 columns">
                                    <button type="submit" class="button postfix" id="search_submit">Search</button>

                                </div>
                            </div>
                            <div>
                            <label for='search_branche'>Branche</label>
                              <select id='search_branche' name='branche'>
                                <option value=''>Any</option><?php
                                // generate the Branche options, checking the whitelist to see if any are already selected
                                  foreach($pages->get("/branche/")->children() as $branche) {
                                       $selected = $branche->name == $input->whitelist->branche ? " selected='selected' " : '';
                                       echo "<option$selected value='{$branche->name}'>{$branche->title}</option>";
                                  }
                                ?>
                              </select>
                            </div>
                        </form>

This is the search.php:

$out = '';

// if a branche is specified, then we limit the results to having that branche (branches field in those pages)
if($input->get->branche) {
    $branche = $pages->get("/branches/" . $sanitizer->pageName($input->get->branche));
    if($branche->id) {
        $selector .= "branches=$branche, ";//CHANGE YOUR SELECTOR AS SHOWN HERE
    $summary["branche"] = $branche->title;
    $input->whitelist('branche', $branche->name);
    }
}


if($q = $sanitizer->selectorValue($input->get->q)) {

    // Send our sanitized query 'q' variable to the whitelist where it will be
    // picked up and echoed in the search box by the head.inc file.
    $input->whitelist('q', $q);

    // Search the title, body and sidebar fields for our query text.
    // Limit the results to 50 pages.
    // Exclude results that use the 'admin' template.
    $matches = $pages->find("title|body|sidebar~=$q, limit=50");
    $count = count($matches);

    if($count) {
        $out .= "<h2>Found $count pages matching your query:</h2>" .
            "<ul class='nav'>";

        foreach($matches as $m) {
            $out .= "<li><p><a href='{$m->url}'>{$m->title}</a><br />{$m->summary}</p></li>";
        }

        $out .= "</ul>";

    } else {
        $out .= "<h2>Sorry, no results were found.</h2>";
    }
} else {
    $out .= "<h2>This is from my search.php page</h2>";
}

// Note that we stored our output in $out before printing it because we wanted to execute
// the search before including the header template. This is because the header template
// displays the current search query in the search box (via the $input->whitelist) and
// we wanted to make sure we had that setup before including the header template.

include("./myinclude/head.inc");

echo $out;

include("./myinclude/foot.inc");
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...