Jump to:

22977 Posts in 11657 Topics by 2827 members

General Questions

SilverStripe Forums » General Questions » Update Field with another.

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

Page: 1
Go to End
Author Topic: 916 Views
  • sca123
    Avatar
    Community Member
    61 Posts

    Update Field with another. Link to this post

    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

  • ChrisBryer
    Avatar
    Community Member
    95 Posts

    Re: Update Field with another. Link to this post

    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

  • sca123
    Avatar
    Community Member
    61 Posts

    Re: Update Field with another. Link to this post

    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

  • ChrisBryer
    Avatar
    Community Member
    95 Posts

    Re: Update Field with another. Link to this post

    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?

    916 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.