Jump to content

[SOLVED] Add dynamic filtering content with dropdown in Skyscrapers


gregory
 Share

Recommended Posts

Hi guys.
In Skyscrapers search-form.php, I have added a select to filter the contents based on an Option (type) field.

				<div class='uk-form-row'>
					<label class='uk-form-label' for='search_tipologia'>Tipologia</label>
					<div class='uk-form-controls'>
						<select id="search-tipologia" name="tipologia" class="uk-select">
							<option value="">Qualsiasi</option>
								<?php
									foreach(array('Bed and Breakfast', 'Agriturismo', 'Masseria', 'Hotel') as $range) {
										$selected = $range == $input->tipologia ? " selected='selected'" : '';
										echo "<option$selected value='$range'>$range</option>";
									}
								?>
						</select>
					</div>
				</div>

In the search.php template how can I retrieve the contents?

$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(
	"city" => "",
	"height" => "",
	"floors" => "",
	"year" => "",
	"keywords" => "",
	"tipologia" => "",
	);

// if a city is specified, then we limit the results to having that city as their parent
if($input->get('city')) {
	$cityName = $sanitizer->pageName($input->get('city'));
	$city = pages("/cities/$cityName/");
	if($city->id) {
		$selector .= "parent=$city, ";
		$summary['city'] = $city->title;
		$input->whitelist('city', $city->name);
	}
}

// if a tipologia is specified how to show the content?
if($input->get('tipologia')) {
<------------------------>
}

// we are allowing these GET vars in the format of 999, 999-9999, or 999+
// so we're using this loop to parse them into a selector
foreach(array('height', 'floors', 'year') as $key) {

Thank You in advance.

Link to comment
Share on other sites

1 hour ago, gregory said:

In the search.php template how can I retrieve the contents?

Do you mean how you can build the selector for the options field?

 

1 hour ago, gregory said:

// if a tipologia is specified how to show the content?

Carrying on from above, do you mean how to build the selector? If yes, just append a SANITIZED value (from $input->tipologia) to query your options field as well. E.g. $selector .= "name_of_options_field={$sanitizedTipologiaSekectorValue}".

Typed quickly in browser and untested.

  • Like 1
Link to comment
Share on other sites

31 minutes ago, kongondo said:

Do you mean how you can build the selector for the options field?

I think I have solved it this way thanks to your suggestion.

if($input->get('tipologia')) {
	$value = $sanitizer->selectorValue($input->get('tipologia'));
	$selector .= "tipologia={$value}, ";
	$summary["tipologia"] = $sanitizer->entities($value);
	$input->whitelist('tipologia', $value);
}

 

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...