0

I have a rule that sends the contents of a node to an email address on save, I am including the contents of the mail with tokens. However, if the field is blank then instead of not showing, the token itself shows in the email. Is there any way to prevent this from happening, or include all the fields in one token?

1 Answer 1

1

you may use PhP in your send mail rule action to check if your field is empty.

Be careful it's a bit tricky because token is not actually empty when the field is empty, it's just not computed, as you saw when you tested.

Unfortunately, the token will be rendered, if field not empty, whatever you put around it in PhP, even ' or ".

So, it's not really clean, but the way I see it is explode and then check whatever you want (for my part I use here only the first part, "[node") :

<?php
// Explode your token (or your value, you don't know yet)
$a = explode(':',"[node:body]");

// Check if first part is [node
if($a[0] != '[node') { ?> 

[node:body]

//Don't forget to close the if() statement
<? } ?>

Not very good if you have to check this on many fields, NOT CLEAN at all in fact, but working :D

4
  • this is for a D6 site, so could be the problem? Dec 10, 2012 at 12:53
  • Damned ! Didn't see it was D6... Can you try it though ? It might work the same way... Dec 10, 2012 at 13:33
  • I did try but I don't think that php is evaled. I know that it is possible in D7 to eval php so you were likely correct. Dec 10, 2012 at 13:58
  • Do you have php filter module (I guess it is in core) enabled ? Dec 10, 2012 at 14:28

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.