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.

All other Modules /

Discuss all other Modules here.

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

Member Profile: user relationship form null ID


Go to End


321 Views

Avatar
ilTuoBrand

Community Member, 1 Post

3 October 2017 at 5:23am

Fatal error: Call to a member function Services() on null

it's correct?
Member::get()->byId($this->urlParams['ID'])->Services()->map('Title','Title')
thanks for the help!

class MemberProfileViewer extends Page_Controller {

    // ...

public function form() {

    $fields = new FieldList(
        CheckboxSetField::create(
            $name = "ServiceID",
            $title = "Select",
            $source = Member::get()->byId($this->urlParams['ID'])->Services()->map('Title','Title')
        ),
    )

    $actions = FieldList::create(
            FormAction::create('form', 'Send')
                ->setUseButtonTag(true)
                ->addExtraClass('btn btn-primary')
    );

    $validator = new RequiredFields('ServiceID');

    $form = new Form($this, 'form', $fields, $actions, $validator);
    $form->setFormMethod('POST', true);
    return $form;
}

public function doform($data, $form) {
    $form->sessionMessage(
        "Thank you, you will be contacted as soon as possible by our consultant.", 'good'
    );

    $submission = new RequestForm();
    $form->saveInto($submission);
    $submission->write();

    return $this->redirectBack();

}