Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Top Level Pages dropdownfield


Go to End


4 Posts   516 Views

Avatar
Praveen

Community Member, 49 Posts

1 October 2014 at 9:01pm

Edited: 01/10/2014 9:03pm

I need to add the DropDownField to the searchform which shows only the pages from the top level. Even I want to restrict the pages from the toplevel to list only specific pages.
How to do that? I did not get useful links or document .Please help
function SearchForm() {
$searchText = isset($_REQUEST['Search']) ? $_REQUEST['Search'] : 'Search';
$fields = new FieldSet(
new TextField("Search", "", $searchText)
new DropdownField("PageID", "", Dataobject::get("ContentPage")->map("ID", "Title", "Please Select"))
);
$actions = new FieldSet(
new FormAction('results', 'Search')
);

return new SearchForm($this->owner, "SearchForm", $fields, $actions);
}

Avatar
Praveen

Community Member, 49 Posts

1 October 2014 at 9:28pm

I listed the top level pages new DropdownField("PageID", "", DataObject::get("SiteTree", "\"ShowInMenus\" = 1 AND \"ParentID\" = 0")->map("ID", "Title", "Please Select"))

<option value="2">Company</option>
<option value="3">Film</option>
<option value="7169">Advertising</option>
<option value="17880">Forum</option>
<option value="15">Technical Support</option>
<option value="17885">Wiki</option>
<option value="5299">Training</option>
<option value="17882">Forum</option>
<option value="4281">Security</option>

How could I filter to show only pages Company,Film and Advertising?

Avatar
martimiz

Forum Moderator, 1391 Posts

1 October 2014 at 10:45pm

Could you not just add a boolean field ShowInSearchDropdown to the Page class settings? That way you can add whatever page you want...

Avatar
Praveen

Community Member, 49 Posts

2 October 2014 at 12:00am

Thank you giving a thought of adding a ShowInSearchDropdown column to the table. I would try that later currently I am modifying the code to

DropdownField("PageID", "", DataObject::get("SiteTree", "\"ShowInMenus\" = 1 AND \"ParentID\" = 0 AND Title NOT IN ('Technical Support','Forum','Wiki')")->map("ID", "Title", "Please Select"))

This still works to me.