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.

Form Questions /

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

Problem with search and scaffolded searchform


Go to End


9 Posts   4933 Views

Avatar
javelin

Community Member, 12 Posts

27 April 2010 at 11:09pm

Edited: 27/04/2010 11:09pm

This became more complicated than i thought. :-(

Filtering while searching is of course much better. Should have thought about that. Thank you guys.
But i cannot push a new Hiddenfield into the searchform since that value doesn't exist in the searchContext. Even if I do that the search ignores that field.

I guess it would be possible to push something similar into $context but that is to complex of a variable for me to understand when i print_r it.

Adding a new value to searchable_fields on the dataobject (so that it will be included in defaultSearchContext) works. I can then remove the field from the form and then add the key-value pair again right before doing the search:

$context = singleton('Apartment')->getDefaultSearchContext();
//Add fields so that only published are shown and only related.
$data['ApartmentStatus'] = "Publicerad"; 
$data['ApartmentListID'] = $this->ID; 
$results = $context->getResults($data);

Thanks again!

Javelin

Go to Top