3

I've used the front-end entry form in the docs to build a Q&A portal, and it's working great. But I'd like to extend the functionality once the new entry is saved.

I've set the entries up to not be enabled when saved so that a moderation team can later approve them. Is there a way for members of the moderator user group to receive an email every time someone publishes a new question via the front-end form?

  • Are you posting these front-end entries to a custom plugin controller's action or are you going straight through Craft's entries/saveEntry? – Brad Bell Dec 30 '16 at 23:49
  • I'm going through entries/saveEntry. – Jeremy Fuksa Jan 2 '17 at 17:04
2

You can write a simple plugin that listens for the onSaveEntry event.

When that event fires, you plugin could check the $isNewEntry param to make sure it's a new entry being saved and also check the entry's section to make sure it's the front-end section you're expecting and might as well check craft()->request->isSiteRequest() to make sure it's a front-end request.

If all of those match, you would get the users in a group, then loop through all of them sending an email with craft()->email->sendEmail() for each user.

Something like (pseudocode):

$element = craft()->elements->getElementType(ElementType::Users);
$element->group = 'groupHandle';
$users = $element->find();

foreach ($users as $user)
{
    // compose email body, header, etc.
    $success = craft()->email->sendEmail($email, $variables);
}

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.