Jump to content

Drop down select to search form


Alexander
 Share

Recommended Posts

Sorry for this dummy question, I'm newbie for processwire.

I try to make new field for search form from "drop down module" but nothing happens.

Take a look:

<select id='country' data-placeholder="Country" placeholder="Country" name='country'>

<option value=''></option><?php 

foreach($country as $count){

$selected = $count == $input->whitelist->country ? " selected='selected' " : ''; 

echo "<option value='$count'>$count</option>";}

?>

</select>

What am I doing wrong?

Cheers, 

a.
Link to comment
Share on other sites

The posted code example looks okay to me. But I'm not sure I understand the question… What is the "drop down module"? We'd probably also want to see where $country is coming from and where you are setting $input->whitelist->country. But most importantly, what is the expected output, and what output are you currently getting?

You need the curly brackets around count.

Curly brackets only necessary if you've got two "->" in there, meaning, you can do this:

echo "$page->title";

but not this

echo "$page->image->width";

you'd have to do this: 

echo "{$page->image->width}";
  • Like 1
Link to comment
Share on other sites

<select id='country' data-placeholder="Country" placeholder="Country" name='country'>

<option value=''></option>
<?php
$selOptionsArray = preg_split('/\n/', $fields->country->select_options);

foreach ($selOptionsArray as $country) {
  $parts = preg_split('/:=/', $country);
  $selected = $parts[0] == $input->whitelist->country ? " selected='selected' " : ''; 
  echo "<option$selected value=\"{$parts[0]}\">{$parts[0]}</option>";
}

?>
</select>

Great thanks to everybody for your help!

So, I'm just trying to make search "select" from select (AKA drop down) module.

It's not so easy (:

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