The purpose here, is to add a "Manager" in frontend to allow administrator to modify items (subject, body, recipient) of each email notifications of your website.

For that, we'll need to do 3 task:

  • Create an Email Option content type
  • Create an Email Option Manager (Search type)
  • Adapt all your forms to get good items depending on defined parameters (Menu Item, category,...)

Create a Content Type "Email Option"

In this content type add the differents fields which must be modified by administrator, like :
  • Subject : Text
  • Confirmation Author body : wysiwyg
  • Notification Admin body : wysiwyg
  • Recipient(s): Text or FieldX

Add also, some fields to be able to retrieve those informations from all your forms where emails must be send.
For example, If all your forms are affected to a menu Item, you can add a field "JFom - Menu Item" or also category field, or what you want.
In this example, 2 fields are added to be able to find good email body from differents form:

  • Function : Menu item
  • English Category : category

Then create an Email Option Content for each forms which send email in the website.

Create the Manager

Genrate a search type based on the previous content type, and display all previous content in a tab, with an edit button by row.

Adapt all your forms

In each form where you want send email, and so get options, you must add some extra fields and configure correctly your Email field(s). An email field allow you to specify that the subject / Body / Recipients can be getted from other fields in the form.

So the purpose here is to setup email field with name of options fields:

The Options fields don't need to have a storage, they are just here to be a buffer for emails fields where they will get their content:

For exemple, this contact form is configured to get options for two Email fields:

Email Confirmation to the author

  • FC Ask Author Confirmation : the email field
  • FC Ask Author Body : to get the body from the option

Email Notification to administrator

  • FC Ask Leader Notification : the email field
  • FC Ask Leader Body : to receive the body from the option
  • FC Ask Leaders Find Email : to get recipients from the option

An Email field is sending the mail in event " Afterstore", so the purpose is to add a field Code "Afterstore" before all emails fields, for setting each Option field, by requesting the database, depending on menu item, or category...

In an Afterstore fields, we have an array of all fields of the form in the variable "$fields". So to set a field, you just have to set it's property "value", like that :

$options = requestDatabase to get options from Email Option contents WHERE Menu Item = xx
$fields['seb_fc_ask_leader_body']->value = $options->body;
$fields['seb_fc_ask_leader_find_email']->value = $options->recipients;

You can allow administrator to set some dynamic variables in options, like #username#, #whatyouwant#.

By cons, if you allow dynamic variables, you must manage them in the afterstore fields and replace them by the good values, like:

$user = JCck::getUser();
$fields['seb_fc_ask_leader_body']->value = str_replace( '#username#', $user->username, $options->body );<br>

Like we set options fields before Email fields are executed, they can be field with good options.

It's just one way to have this functionality on his website, probably some other ways can do the same.