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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

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


45 Views

Avatar
bitshop

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();

}