Custom Search Form for ListViewer

3 posts by 2 authors in: Forums > CMS Builder
Last Post: February 27, 2008   (RSS)

By Dawna - February 27, 2008

I am using a code similar to this on one of my ListViewer pages and it works great but we will need to provide the pre-defined list of catogories to run the search. Can you provide the code that allows me to include a pre-defined drop down box for the search? [;)]

<form method="get" action="<?php echo $_SERVER['PHP_SELF'] ?>">
Categories: <input type="text" name="category" value="" size="15">
<input type="submit" name="" value="Search">
</form>

Re: [Dawna] Custom Search Form for ListViewer

By Dave - February 27, 2008

Sure, there's no automatic way to do that but it's possible with some PHP code. Try this:

<select name="category">
<?php
$tablename = $options['tableName'];
$fieldname = 'yourFieldName';
$schema = loadSchema($tablename);
$fieldSchema = $schema[$fieldname];
$fieldOptions = getListOptionsFromSchema($fieldSchema);

foreach ($fieldOptions as $valueAndLabel) {
list($value, $label) = $valueAndLabel;
$encodedValue = htmlspecialchars($value);
$encodedLabel = htmlspecialchars($label);
print "<option value='$encodedValue'>$encodedLabel</option>\n";
}
?>
</select>


Just page that where you want your dropdown list and change the fieldname to match yours and it should work.

For more details, have a look at this thread:
http://www.interactivetools.com/iforum/P59787

Let me know if you have any trouble with that.
Dave Edis - Senior Developer
interactivetools.com