Forums

Customized email template based on drop down selection

dkmartin 02 Apr, 2010
Hi,

First off, as a complete noob with php, javascript, I love this component! I started using it a couple weeks ago and it is by far one of the easiest yet extremely powerful form solutions for Joomla. I have scoured the forums for help and am still quite lost. Maybe if someone can post some sample code or at least point me in the right direction that would be greatly appreciated!!

I have built a website for an online math journal to allow submission of manuscripts (pdf files) for review and eventual publication. On the manuscript submission form the user can select an editor from a drop down list to review his manuscript. On submission of the form, the chosen editor receives an email containing the pdf file (figured this out from FAQ#31). The editor then has to be able to select an associate editor within his specific area of research. I have created 5 different forms for each group. What I need is to customize the email template (or use multiple email templates) so that if the user selects editorA, then editor A will get an email with a link to formA in it. If the user selects editorB, then editorB gets an email with a link to formB etc.
GreyHead 05 Apr, 2010
Hi dkmartin,

I see where you've gone with this. I think I would have a slightly different approach . . .

I usually start from the place that having several similar forms is a potential maintenance problem that I could do without. So my inclination is to build a single form and parameterise it.

In this case I'd add a form identifier to the URL in the email and use this to show the correct version of the form - or in your case perhaps to re-direct to the correct form.

To customise the Email Template my preferred method is to define a variable in the OnSubmit Before box (where you are selecting the email addresses) and then refer to that in the template.

So you might have
<?php
switch ($some_variable) {
  case 'A' :
    $link = 'some link';
    break;
  case 'B' :
    $link = 'some other link';
    break;
  case 'C' :
    $link = 'yet another link';
    break;
. . .
}
JRequest::setVar('link', $link);
?>

Then you can use {link} in the Email Template itself.

Bob
dkmartin 07 Apr, 2010
Hi, thanks for the response. I have tried what you said but I'm afraid my lack of coding experience is getting the best of me. I used the code you provided in the onsubmit before box, but all I get in the email is the actual text "{link}" rather than the url i set up in the variable. Here is my form code (actual emails and links have been removed for privacy):


<?php
$emails_2 = array(
'A' => 'a@amail.com', 
'B' => 'b@bmail.com', 
'C' => 'c@cmail.com',
'D' => 'd@dmail.com',
'E' => 'e@email.com');
$MyForm =& CFChronoForm::getInstance('submit_cma');
$MyFormEmails =& CFEMails::getInstance($MyForm->formrow->id);
$MyFormEmails->setEmailData(1, 'to', $emails_2[$_POST['co_edit']]);
?>
<?php
switch ($some_variable) {
  case 'A' :
    $link = 'linkA';
    break;
  case 'B' :
    $link = 'linkB';
    break;
  case 'C' :
    $link = 'linkC';
    break;
  case 'D' :
    $link = 'linkD';
    break;
  case 'E' :
    $link = 'linkE';
    break;
. . .
}
JRequest::setVar('link', $link);
?>


What other steps are needed to get this to work properly? I'm not sure how to include a form identifier in the URL.
This topic is locked and no more replies can be posted.