Return form widget data to model, but do not save

Hello,

I would like to access my form widget data in my models beforeCreate method, but I don’t want to save the data out of the form widget.

Here’s my getSaveValue:

public function getSaveValue($value)
{
        if (isset($value) && is_array($value)) {
            return $value;
        } else {
            return [
                'action' => 'no_action'
            ];
        }

        return \Backend\Classes\FormField::NO_SAVE_DATA;
}

When I put an underline in my form field, the $value is null in the beforeCreate method:

public function beforeCreate()
{
        dd($this->sozjobs); // is null, when field name is _sozjobs
        ...
}

Here is my field:

sozjobs:
    label: sozjobs.ch
    span: full
    type: sozjobs

Yes, you’re telling the widget not to return any data. The best approach then would be to use post() to access the data from the model. Data usually sits in the model name’s array, so if the model is Foobar then you can find the field in

dd(post('Foobar[sozjobs]'));

I hope this helps

1 Like