I'm having troubles with the following: I created a form with entityforms and now i want to send a confirmation email with mimemail. Getting that to work is no problem.

But i need to perform a small check with the php evaluation function of mimemail.

The form is for customers to place an order, but they have to specify 1 of 2 printing techniques available, 'fdm' or 'polyjet'. This is a 'list' field in the entityform with the two options. And in the confirmation email i need to check what technique has been chosen so i can display some lines of text depending on the technique.

For my php evaluation i would like to get the key (machine readable name) of the submitted value.

So i can do something like this:

switch ($chosenkey){
    case "pol":
        echo "lines of text for polyjet";
    case "fdm":
        echo "lines of text for fdm";
        echo "error";

So basically i just need to know how i can create a variable ($chosenkey) that contains the submitted key of the chosen printing technique.

anyone any idea how i can accomplish this? I have googled around but can't find any relevant answer.

  • you would check the $form_state in the form's hook_submit function. If you want to in addition send an email when submitting the default form. You need to alter the form using hook_form_alter and append your own submit handler onto the form to then sent your email.
    – tenken
    Jul 14, 2015 at 14:54

2 Answers 2


I'm not familiar with entityform so forgive me if none of this makes sense, but I imagine it works much like webform in that it sends the e-mail to the addresses you set up upon a successful form submit with no need for any custom code. So adding another validator or submit function to send the e-mail would result in two e-mails.

What you can do is use hook_mail_alter in a custom module and see what variables entityform passes to its drupal_mail call. With any luck, all the form values from $form_state will be included and you can do the check there and then change the $message['body'] array accordingly.

In the hook_mail_alter you can do a switch statement for the $message['key'] or $message['id'] to make sure you're not running your check for every mail your drupal site sends but only for the entityform in question.

I would also include a custom token of sorts in the template you, presumably, entered when settings up the entityform so you can easily change the e-mail body once you've run the check. I don't know if you could do it with Drupal's Token system, but even just entering 'my_module_custom_token' in the template and then using str_replace on 'my_module_custom_token' with the correct sentence in the mail_alter is better than nothing.

If none of this applies, then naturally disregard this answer entirely.


Thank you for helping.

Problem is that the check i wan't to do is very simple and i'm not looking to write an extra custom module for it. It looked to me that MimeMail has build in PHP evaluation for simple tasks. And the thing i wanted to accomplish looked simple to me.

After a lot of trial and error (my PHP knowledge is very basic) i have found a solution to my problem.

Getting the key of a submitted value works like this:

    $values = field_get_items('entityform', $entity, 'your_field_name');
    $value = $values[0]['value'];

This code gets me the key that i need to perform a simple check like this:

<? if($value == "key1"){ ?>line of text for key 1<? }else{ ?>line of text for key 2<? } ?>

Everything works fine now and in my case my problem got solved :)

Thanks again!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.