I have two plugins that I want to use in a single form. One is a Guest Entry plugin to save the data submitted in the form, and the other is a Plugin that sends an email notification when the form is submitted.

I want to use both of these in the same form but I'm not sure how. If I have

<input type="hidden" name="action" value="guestEntries/saveEntry">
<input type="hidden" name="action" value="formNotification/getForm">

It won't work since both have the name "action" and I can't change the name or the functions never get called.

What can I do to make both of them work?


It’s not possible for a form to simultaneously invoke two controller actions.

You would need to write a plugin that provides its own controller, which in turn could be used to invoke the other controller actions.

class MyPluginController
    public function actionSaveEntryAndSendNotification()
        // Save the entry

        // Send the notification

If "FormNotificationController" is already your own custom plugin, then it might make more sense to just call craft()->runController('guestEntries/saveEntry'); from the top of actionGetForm(). Or just save the entry yourself from the controller action – the Guest Entries plugin is really pretty simple; most of the heavy lifting is provided by the EntriesService - saveEntry() API.

| improve this answer | |

You can't run multiple actions in one request. What you're looking to do is trigger your notification action after the entries.saveEntry event. I'm assuming that your formNotification plugin is a custom plugin that you wrote. Fortunately, events are easy:

craft()->on('entries.saveEntry', function(Event $event) {
    // Your notification code here.

The best place to add this event listener is in your plugin's init function. This is located in the main plugin file.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.