I'm a bit confused by the "Recipients" section on the form used to fill out an email. If I've already selected the users to receive the email with their associated email addresses, why do I have to select the field to use for the email address? This seems like a UX error in design. Is there any way I can pre-select the filed, or, do it through code? I've had this tested by some of my users, and, I have to agree with them. It doesn't make sense to select the people and email addresses and then be forced to select the email "field" to use from the view.

Comments

rrirower created an issue. See original summary.

hansfn’s picture

Status: Active » Fixed

Sorry about the late reply - I just forgot this issue.

The reason is two-folded:

  • If the user doesn't select it, the module has to guess which field contains the email address. Yes, you could probably do that by going through each field and check if the field contains a valid email address. Probably robust enough. You can't do it by looking at the field type or name - doesn't work.
  • A view can contain multiple fields with email adresses. (Not very common, but I can easily see a use case - a view containing both a private and work email.)

You should probably take a look at #2493363: Simplify send interface for non tech-savvy users. The very last comment contains some sample code. Or use something like the following to pre-select the recipient:

function mymodule_form_alter(&$form, &$form_state, $form_id) {
    if (strpos($form_id, 'views_form') === 0) {
        if (!empty($form['from']['views_send_from_mail'])) {
            // You need to change "users_mail_pos_1" below. 
            // "users_mail" is the name Views has assigned to the field.
            // "pos_1" is for the position of the field in the views. 
            // (First field "pos_0", second field "pos_1" and so on.)  
            $form['to']['views_send_to_mail']['#default_value'] = 'users_mail_pos_1';
        }
    }
}

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.