mplodowski / formbuilder-plugin-public

https://octobercms.com/plugin/renatio-formbuilder
https://octobercms.com/plugin/renatio-formbuilder
2 stars 0 forks source link

Hidden field with page title or slug, url #47

Closed petrsiroky closed 4 months ago

petrsiroky commented 4 months ago

Hi, please advice and maybe an idea for a new field. Is there some way to submit a custom variable along with the form using a hidden field or creating a custom field. In the form I need to send the title or slug or url of the page from which the form is sent.

Thank you

mplodowski commented 4 months ago

In the latest version I added hidden field type, so you can use it.

This code should work:

\October\Rain\Support\Facades\Event::listen('formBuilder.overrideField', function ($field) {
    if ($field->name === 'my_hidden') {
        $field->default = request()->url();
    }
});

You can also use formBuilder.beforeSendMessage event to override $data sent with form.

This code can be used in page php section or custom plugin boot method.

petrsiroky commented 4 months ago

great, thanks for the quick reply. That should work