Forums

How include date field contents in e-mail subject text

pattaya2000 16 Jan, 2010
Hi

My form includes a field where customers will enter their preferred delivery date.
I would like the subject line of the e-mail that is generated by the form to consist of ...

"<fixed text of my choice> <delivery date field contents> <fixed text of my choice>"

Please could someone tell me how I can do it (if it is possible at all)?

Thanks in advance

Simon
nml375 16 Jan, 2010
Hi Simon,
Something like this should do the trick, if placed in the "On Submit - before email" box:
<?php
$MyForm =& CFChronoForm::getInstance('formName');
$MyFormEmails =& CFEMails::getInstance($MyForm->formrow->id);
$MyFormEmails->setEmailData(1, 'subject', 'Start of subject' . JRequest::getString('deliveryDate') . 'end of subject');
?>

Just remember to change 'formName' to match the name of your form, and 'deliveryDate' to what you named your date-field. The above code will alter the first email template in your form, change the 1 in the setEmailData() method if you have multiple email templates and need to alter one of the other ones.

/Fredrik

Edit: Ohh, seems Bob beat me to it...
pattaya2000 16 Jan, 2010
Many thanks guys. The e-mail subject line I want to end up with is ...

Roses-To-Pattaya.com Pending Order for delivery on <delivery date> - Waiting for Payment

I don't know if I have multiple email templates. How can I tell?

I want the form to send an e-mail to various e-mails addresses (which already works), so I have used the following fields in Step 2 (Choose Emails(s) Settings) of the wizard for this particular form ...

To
Dynamic To
CC
BCC
Fromname
FromEmail

My form name is Order_Form
I have customised the template content in Step 3 of the wizard
I am using a Redirect URL in Step 4 of the wizard but nothing in the After Submit box
I only have one other form on my website created with Chronoforms (one called Contact_Us)

Please could you could give me the exact code I need?

Simon
nml375 16 Jan, 2010
Hi Simon,
Unless you've created more than one email under the Email Setup, there's just the one. If you feel unsure, please post a screenshot of your email setup tab.
I would need the exact form field name of the date input for the complete code. Given the information provided, the updated code would be as follows:
<?php
$MyForm =& CFChronoForm::getInstance('Order_Form');
$MyFormEmails =& CFEMails::getInstance($MyForm->formrow->id);
$MyFormEmails->setEmailData(1, 'subject', 'Pending Order for delivery on ' . JRequest::getString('deliveryDate') . ' - Waiting for Payment');
?>


You'd still have to replace 'deliveryDate' with whatever you named your date entry in your form though...

/Fredrik
pattaya2000 17 Jan, 2010
Sorry to have to ask, but where is the email setup tab? In Chronoforms GUI? In Joomla Global Config?
I cannot see one anywhere.

The name of the field my customers will used to enter a delivery date is {text_28}
pattaya2000 17 Jan, 2010
Maybe I found it - does the attached screenshot help?
nml375 17 Jan, 2010
Hi Simon,
That would be the "Step 2 (Choose Email(s) Settings)" step in the Wizard, or the "Setup Emails" in the standard Form Edit (Right where you add the To, From Email, From Name, Subject, etc). If you've got a single green box with the details for sender, recipient, and subject, then you've got a single email template. If you have several boxes, then you've got multiple email templates.

Edit: Yep, that's the one.

Updated code (goes into the "On Submit - Before Email" setting under the Form Code tab of the Form Editor):
<?php
$MyForm =& CFChronoForm::getInstance('Order_Form');
$MyFormEmails =& CFEMails::getInstance($MyForm->formrow->id);
$MyFormEmails->setEmailData(1, 'subject', 'Pending Order for delivery on ' . JRequest::getString('text_28') . ' - Waiting for Payment');
?>


/Fredrik
pattaya2000 18 Jan, 2010
Thank you very much. I have managed to make it work correctly. But I had some trouble along the way ...

- I received no e-mails at first. Removing the (static) Subject box in Step 2 of the wizard seemed to disable e-mails
- I had to check the other post (for which the link is mentioned above) to ensure that I had the necessary Dynamic Subject field in the box for Step 2 with the contents "subject"
- Making the changes messed up my modified e-mail template in Step 3 of the wizard, so I had to recreate
- Took me a while to figure out how to enable e-mails again (check the Email properties of each item in the box in Step 2 of the wizard

Anyway got there in the end!

Unfortunately I have 1 unrelated issue and 1 question which I will create new posts for

Best Regards

Simon

Simon
GreyHead 18 Jan, 2010
Hi Simon,

You must have 'To', 'Subject', 'From Namne' and 'From Email' or the dynamic equivalents with acceptable values in the boxes before you can enable the Email Setup.

Bob
pattaya2000 18 Jan, 2010
Thanks Bob.

As mentioned above, I've got it working now. I was just explaining a few issues I had during the process of getting it to work
This topic is locked and no more replies can be posted.