0

I have a webform and i want to send by mail this webform to submitter. For the moment, i created an hidden field with token [current-user:mail] and i chose this field in adress. I think it isn't very well. Can I do it in hook_form_alter ? if yes, how to do it?

  • I think you can use Rules and Webform Rules module in combination to send mail, which drupal version are you using? – CodeNext Aug 11 '16 at 14:44
0

You can set a e-mail field in the webform, whether it is hidden or not is up to you. You should then set the current users e-mail address as the default value. For this, you will need hook_form_alter()

function YOURMODULE_form_alter(&$form, $form_state, $form_id) {
  //drupal_set_message($form_id); (uncomment this to get form id)
  if ($form_id == 'your_webform_id') { 
    global user;
    if ( $user->uid ) { //check user is logged in
    $form['field_email']['und'][0]['value']['#default_value'] = $user->mail;
    }
  }
}
  • Thanks for your response. Do you have a solution to send email without use of field in webform ? – cel57 Aug 11 '16 at 13:40
  • Would the webform submitter always be logged in? Otherwise you wouldnt have the email of an anonymous user – Collins Aug 11 '16 at 19:07
  • yes, the webform submitter who is logged in. – cel57 Aug 11 '16 at 19:46
  • 1
    Try installing drupal.org/project/webform_rules and rules, and create a rule for "after webform is submitted" to send to the current user who submitted it. – Collins Aug 11 '16 at 20:35
0

enter image description here

In Drupal 8 you can go to webform settings-> email/handler -> add email then select current user email address for To email.

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.