This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

admin15190
admin15190

I am using the builder plugin form and I simply want to get the value from field a and update field b +1

eg a=1, b=2 (a+1)

I have tried defaultFrom, trigger but I just can't get it to work. What am I missing?

Thanks

admin15190
admin15190

Figured it out myself, sort of.

I don't think you can do it with the builder form but if you edit the model php file

you can do it using the beforeCreate function

public function beforeCreate() { $this->b = $this->a+1; }

Hope this helps someone

Last updated

philipptempel
philipptempel

That is correct. The builder is only useful to quickly and nice build the models. Anything application specific like your code here would require you to edit the model file manually.

Be aware of the beforeCreate() method though. It will be run once and only once when the model is being created. It will not run whenever it is being updated. Here beforeSave() would be smarter - depending on the meaning of your model's property $b

admin15190
admin15190

Cheers Philipp, I will bear that in mind.

1-4 of 4

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.