Jump to content

Search form by page feild


Ollie
 Share

Recommended Posts

Hi there,

I am struggling to work out something that i know should be really simple but its just not working out for me! 

I have set up images manager and i need to be able to search on the user side only through the image pages that get created with images manager, the thing is I need it to search by a page feild called imageTags.

Here is the set up as I dont think i am explaining myself too well!

images

Category 1

Image 1 -> this has a page list multiple select that is selected from imageTags

Image 2     "                                                 "                                                    "

Image 3     "                                                 "                                                    "

 

imageTags

tag1

tag2

tag3

 

So when searching it needs to output an image page based on a search through that pages imageTags!

Here is what I have But its probably far off!

<?php

$out = '';

if($q = $sanitizer->selectorValue($input->get->q)) {
    $input->whitelist('q', $q);
    $matches = $pages->find("image.imageTags%=$q, limit=20");

    $count = count($matches);

    if($count) {
 
        $out .= "<h2>Found $count pages matching your query:</h2>" . 
            
}
} else { $out .= "<h2>Sorry, no results were found.</h2>"; } } else { $out .= "<h2>Please enter a search term in the search box (upper right corner)</h2>"; }
include("./head.inc"); 
 
echo $out; 
 
include("./foot.inc"); 

And the search form is this:

<form class="search-form" id='search_form'  action='<?php echo $config->urls->root?>search/' method='get'>
<input type='text' name='q' id='search_query' placeholder="Search" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Search'" value='<?php echo htmlentities($input->whitelist('q'), ENT_QUOTES, 'UTF-8'); ?>' />
</form> 

Any help is greatly appreciated so a big thanks in advance!

Ollie

 

Link to comment
Share on other sites

I may be completely off, but do not see where you are outputting anything.  Just a disclaimer, I'm still learning myself, but thought I would give it a try. Someone will correct me I am sure :)..

$out = '';
    if($input->get->q) {
     $q = $sanitizer->selectorValue($input->get->q);
          $input->whitelist('q', $q);
       }
        $matches = $pages->find("image.imageTags%=$q, limit=20");
         if(count($matches)) {
          $out .= "<h2>Found $count pages matching your query:</h2>";
            foreach ($matches as $match) {
          $out .= "<a href='{$match->url}'>$match->title</a>";
         }
     }
   else { 
      $out .= "<h2>Sorry, no results were found.</h2>" .
              "<h2>Please enter a search term in the search box (upper right corner)</h2>";
   }
  include("./head.inc");

   echo $out;
Link to comment
Share on other sites

Just a quick one (on a mobile atm). If imageTags is a field on an image page then I guess the selector should be just "imageTags%=$q, limit=20". Does this (with the foreach RJay proposed) solve the issue?

  • Like 1
Link to comment
Share on other sites

No luck guys! I am getting this error message but I have no idea what it means:

Error: Exception: Unknown column 'field_image.imageTags' in 'on clause' (in myurl.com/html/wire/core/Database.php line 118)

and for just using "imageTags":

Error: Exception: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '='blue' 

JOIN field_imagetags AS field_imagetags ON field_imagetags.pages_id=pag' at line 3 (in in myurl.com/html/wire/core/Database.php line 118)

Thanks for trying!!

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

×
×
  • Create New...