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.

General Questions /

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

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

Update Field with another.


Reply


4 Posts   1123 Views

Avatar
sca123

Community Member, 61 Posts

12 December 2009 at 11:32am

Ok, what I would like to do is automatically update the [Content] field with data from two other CMS fields called [OrphanageName] and [Gender].

This is so that these items will be searchable by the Silverstripe search module.

Any assistance would be appreciated

Avatar
ChrisBryer

Community Member, 95 Posts

12 December 2009 at 8:06pm

try adding something like this to your page class:

function onBeforeWrite(){
$this->Content = $this->OrphanageName . ' ' . $this->Gender;
parent::onBeforeWrite();
}

i didnt test the code, but it should be close... this will always overwrite Content by the way.
-Chris

Avatar
sca123

Community Member, 61 Posts

12 December 2009 at 11:25pm

Excellent - that works really well.

Do you also know how I can also run a search as an AND rather than an OR??

For example, if I search for Male Mynamar - I still get all females showing from Mynamar.

Any help would be great.

Thanks

Avatar
ChrisBryer

Community Member, 95 Posts

15 December 2009 at 4:18am

not too sure on that one.. you probably will have to extend SearchForm.. theres also an advanced search form class but i've never worked with that, so perhaps it already exists?