Jump to content

Search facility to show repeater fields in a pop up modal


Recommended Posts

Hi Guys,
I am trying to implement a website that uses processwire as the content management system. I am trying to create a page where stars can be added to a christmas tree, each star is a repeater field and is associated to a modal pop up which displays a message.
There may be more stars than what we can physically put on the tree so I have implemented the search function to allow users to search for a name or message in order to find their star.
At the minute the search function is showing the results from the repeater fields, I have 2 stars at the minute however only one shows in the search results. 1 star has test in all the fields and the other has mel in each of the fields. 
I have no idea why only one result will show, any help would be greatly appreciated.
The link to the page is as follows: http://www.friendsofthecancercentre.com/wish-upon-a-star/


$out = '';

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("star.message|star.who|star.from*=$q,"); 

	$count = count($matches); 

	if($count) {
		$out .= "<h2>Found $count fields 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>Please enter a search term in the search box (upper right corner)</h2>";

Link to comment
Share on other sites

Repeaters aren't a good idea if you're expecting even stars to not fit on the tree. Problem is, that each star will be loaded if you try to open the page containing the stars, which doesn't scale very well. I'd rather suggest using normal pages for stars and using a "tree selector" pagefield to link them to the tree page. To get an overview over all stars in the backend you can then use Lister/Lister Pro, which do scale.

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

  • Create New...