mplodowski / formbuilder-plugin-public

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

Send from to specific e-mail, according to dropdown select box #50

Closed afdstudio closed 1 day ago

afdstudio commented 2 months ago

Is your feature request related to a problem? Please describe.

I need that a form is sent to a specific e-mail as follow:

Client would select a Store Location on the form as shown: Location 1 Location 2 Location 3

Then, the form should be sent to specific e-mail according to location selected. Example: If client selects Location 1, the form should be sent to email_1 If client selects Location 2, the form should be sent to email_2 If client selects Location 3, the form should be sent to email_3

Is there a way to workaround with this feature?

Thank you in advance!

mplodowski commented 2 months ago

You can use page event and plugin event like so:

   function onInit()
    {
        \Event::listen('formBuilder.beforeSendMessage', function ($form, $data) {
            if ($data['location'] == 'Location 1') {
                $form->recipients = [
                    [
                        'email' => 'email1',
                        'recipient_name' => 'name1',
                    ],
                ];
            }
        });
    }
afdstudio commented 3 weeks ago

Hi @mplodowski Thank you very much for your help. It is working. I really appreciate your help!

As I am not expert on coding, can you explain how did I get the option key value (email) selected on dropdown form? With this code, I am getting the "Option Label". If I get the Option Key, it will save me a lot of time.

function onInit() { \Event::listen('formBuilder.beforeSendMessage', function ($form, $data) { if ($data['pontoavic'] == 'Melgaço') { $form->recipients = [ [ 'email' => 'edgarafonso@icloud.com', // option key here 'recipient_name' => $data['pontoavic'], ], ]; } }); }

Captura de ecrã 2024-08-19, às 19 39 58
mplodowski commented 3 weeks ago
\Event::listen('formBuilder.beforeSendMessage', function ($form, $data) {
    $form->recipients = [
        [
            'email' => post('pontoavic')
            'recipient_name' => $data['pontoavic'],
        ],
    ];
});

Remove this first option (none) for empty item and use field placeholder instead. I assume this field is required.

afdstudio commented 3 weeks ago

Hi @mplodowski Thank you! I will try! Great support!