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?


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") :

// 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') { ?> 


//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

  • this is for a D6 site, so could be the problem? – Andrew Welch Dec 10 '12 at 12:53
  • Damned ! Didn't see it was D6... Can you try it though ? It might work the same way... – Gregory Kapustin Dec 10 '12 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. – Andrew Welch Dec 10 '12 at 13:58
  • Do you have php filter module (I guess it is in core) enabled ? – Gregory Kapustin Dec 10 '12 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.