TOPIC:

Custom Email Subject - including value conditionally 2 years 10 months ago #220255

  • Topic Author
  • RIdev
  • Offline
  • Fresh Breezer
  • Fresh Breezer
  • Posts: 17
  • Thanks: 0
I have created a Custom Email Subject in both Admin Emails and Mailback Emails.

But I need to learn how-to make part of the subject conditional.

In the form, the element WhichSponsorship is optional.

ONLY when it is filled in do I want to include as part of the Subject:
(Sponsor: {WhichSponsorship:value})

If the user does *not* check WhichSponsorship then I don't want the output to show:
"(Sponsor: {WhichSponsorship:value})"
I don't even want "(Sponsor: )" appearing.

Please let me know how that's done.

Thanking you in anticipation!
Vicki

Please Log in or Create an account to join the conversation.

Custom Email Subject - including value conditionally 2 years 10 months ago #220310

  • mihaela
  • Offline
  • Developer
  • Developer
  • Posts: 3128
  • Karma: 105
  • Thanks: 415
Hello,

Could you please tell me how you create email template? Do you just report nonempty values or email body if defined differently?
Also, what would you want the subject to be if WhichSponsorship is left empty?

In case you create your own email template, you can achieve what you want if you follow these steps:

1) Create a new textfield element, name it subj

2) Go to Advanced options of your form > More options > Scripts > Initalization Script > set Type to Custom and paste in the following code:
function ff_formname_init()
{
setInterval(calc, 500);

} // ff_formname_init

function calc() {
if(ff_getElementByName('WhichSponsorship').value != "") {
        ff_getElementByName("subj").value ="Sponsor: "+ff_getElementByName("WhichSponsorship").value;
}
else {
        ff_getElementByName("subj").value = "Subject in case WhichSponsorship is empty";
}
}
NOTE: Replace formname with the name of your form. If necessary replace WhichSponsorship with the name of WhichSponsorship field. Also, replace Subject in case WhichSponsorship is empty with the subject that you want.

3) In Admin and Mailback emails set Custom Email subject to {subj}

4) When you see if this works as it should just go to Advanced options of the subj field and Turn it off so it doesn't show in the form.

This will do the trick, but if you just report Nonempty values it will show the additional field as part of email as well, what you don't want I suppose.

I hope this will help you. Let me know then how you create your email and if this solution is working for you.
According to that I will give you further instructions, if it will be necessary.

Regards,

Mihaela

Please Log in or Create an account to join the conversation.

Custom Email Subject - including value conditionally 2 years 10 months ago #220351

  • Topic Author
  • RIdev
  • Offline
  • Fresh Breezer
  • Fresh Breezer
  • Posts: 17
  • Thanks: 0
Hi, Mihaela,
It would be better, I think, if Marko could address this problem because he recently sorted out another, more complex, functionality for me with this form by getting me to send him an exported package... so he saw the whole thing... and this is a small follow-on question which I think he could more easily address.

Anyway, in brief (and not precisely) the structure of the subject in the Admin Email and Mailback Email will have 3 parts:
"Literal text"
"- {fullname:value}" (so that messages thread distinctly in gmail)
then only if the user checked any of the {WhichSponsorship} checkboxes "(Sponsor: {WhichSponsorship:value})"

I hope that's clear.

Please Log in or Create an account to join the conversation.

Custom Email Subject - including value conditionally 2 years 10 months ago #220490

  • marko.bosnjak
  • Offline
  • User is blocked
  • User is blocked
  • Posts: 2222
  • Karma: 44
  • Thanks: 279
Hello Vicki,

unfortunately you won't be able to make those changes in Admin and Mailback areas, because it's not possible to make conditional statements.
You'll have to make the changes directly in the templates.

I attached an example that has the following code implemented, besides the default one:
<?php echo 'Insert your text here!' ?> <?php echo $NL ?>
<?php foreach ($MAILDATA as $DATA): ?>
<?php if($DATA[_FF_DATA_NAME] == 'fullname' && $DATA[_FF_DATA_VALUE] != ''): ?>
<?php echo 'Name'?>: <?php echo basename($DATA[_FF_DATA_VALUE])?><?php echo $NL ?>
<?php endif; ?>
<?php if($DATA[_FF_DATA_NAME] == 'WhichSponsorship' && $DATA[_FF_DATA_VALUE] != ''): ?>
<?php echo 'Sponsor'?>: <?php echo basename($DATA[_FF_DATA_VALUE])?><?php echo $NL ?>
<?php endif; ?>
<?php endforeach; ?>
So, in this line, between single quotes, you should write your text:
<?php echo 'Insert your text here!' ?>
These lines will check if the "fullname" field is empty. If not, it will write the name in the email.
<?php if($DATA[_FF_DATA_NAME] == 'fullname' && $DATA[_FF_DATA_VALUE] != ''): ?>
<?php echo 'Name'?>: <?php echo basename($DATA[_FF_DATA_VALUE])?><?php echo $NL ?>
These lines will check if a checkbox is checked. If so, it will write the correct sponsor in the email.
<?php if($DATA[_FF_DATA_NAME] == 'WhichSponsorship' && $DATA[_FF_DATA_VALUE] != ''): ?>
<?php echo 'Sponsor'?>: <?php echo basename($DATA[_FF_DATA_VALUE])?><?php echo $NL ?>
NOTE: Make sure that "fullname" and "WhichSponsorship" variables match to names of elements in the form.

IMPORTANT: The form's name on my local machine is "TestingForm". The name for the admin email should be "TestingForm.txt.php" and for the mailback email it should be "TestingForm_mailback.txt.php".
You will need to change the names of templates so they match to the form's name.
Paste those 2 files in the /media/breezingforms/mailtpl/ folder.
These templates will work only for that specific form. Other forms will still use the default template.

Try it out and let me know if that is working for you.

Regards,
Marko
======================================
Support Crosstec and get ALL EXTENSIONS and professional support for just $5
Here!
======================================
Need to renew Pro Support?
Buy Here!
======================================
Satisfied?
Consider a Membership!
======================================
Follow us on Facebook!
Attachments:

Please Log in or Create an account to join the conversation.

Last edit: Post by marko.bosnjak.

Custom Email Subject - including value conditionally 2 years 9 months ago #221453

  • Topic Author
  • RIdev
  • Offline
  • Fresh Breezer
  • Fresh Breezer
  • Posts: 17
  • Thanks: 0
Hi, Marko!

Thank you and once again I apologise for the delayed response.

I just placed the code in "TestingForm.txt.php" for Admin Email, and "TestingForm_mailback.txt.php" for Mailback Email into the folder /media/breezingforms/mailtpl/

The output comes through, but there is a problem:
As WhichSponsorship is optional, I've tested with and without checking any value.

When a value is checked, it comes through in the subject line, just as wished. Beautiful!

But when a value is not checked, then this shows up in the latter part of the subject:
(Sponsor: {WhichSponsorship:value})
rather than nothing, which is desired.

Somehow the conditional expression is not right. (I never get this with the name value, because that's a required field... but I guess they're both not right.)

If you can help me fix this, I'd be very grateful!

With great appreciation for your patient and expert help so far,
Vicki

Please Log in or Create an account to join the conversation.

Custom Email Subject - including value conditionally 2 years 9 months ago #221468

  • marko.bosnjak
  • Offline
  • User is blocked
  • User is blocked
  • Posts: 2222
  • Karma: 44
  • Thanks: 279
Hi Vicki,

I just re-tested it and I don't have that issue. Please see attachment:



Could you attach a screenshot of the received email, both when checked and unchecked?

Regards,
Marko
======================================
Support Crosstec and get ALL EXTENSIONS and professional support for just $5
Here!
======================================
Need to renew Pro Support?
Buy Here!
======================================
Satisfied?
Consider a Membership!
======================================
Follow us on Facebook!
Attachments:

Please Log in or Create an account to join the conversation.

Moderators: ForumSupport
Time to create page: 0.206 seconds

BreezingForms Pro 1.4.7 for WordPress Released!

Available in the membership section.

September Discount!

Massive discounts on all subscriptions!

Get Your Subscription Here

Quick Links

Downloads

BreezingForms

ContentBuilder

BreezingCommerce

Templates

Documentation

BreezingForms

ContentBuilder

BreezingCommerce

Apprendre BreezingForms (French Community)

Apprendre et maîtriser BreezingForms par des tutoriels et exemples, le tout en français

breezingforms.eddy-vh.com

Questions et réponses sur les forums de l'AFUJ

AFUJ

Special Offer

Summer Sale! All subscriptions at a special price!

Includes prio support, all of our current and future Joomla!® extensions and Joomla!® templates for the duration of your membership.

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!