2016-10-31 55 views
0

如何根据用户的输入操作忍者形式(3)邮件正文?操作忍者形式邮件正文

例如:

用户填写的zipcode领域,我wan't将数据添加到最近的便利店的邮件正文。

我发现的唯一有用的过滤器是“ninja_forms_submit_data”。但它只返回字段ID和用户输入。

我需要的是一个字段键,所以我可以使用它作为参考。

回答

0

有一个名为ninja_forms_action_email_message的过滤器可用于自定义电子邮件正文。源代码是here

该过滤器具有三个参数:

  1. $message这是当前的电子邮件主体的(HTML)串
  2. $data表格数据(包括有关的形式,并且用户提交数据)
  3. $action_settings PARAMS用于发送电子邮件(至地址等)

例如:

function custom_email_body_content($message, $data, $action_settings) { 
    // You may want to check if the form needs to be customised here 
    // $data contains information about the form that was submitted 
    // Eg. if ($data[form_id]) === ... 

    // Convert the submitted form data to an associative array 
    $form_data = array(); 
    foreach ($data['fields'] as $key => $field) { 
     $form_data[$field['key']] = $field['value']; 
    } 

    // Do something to the email body using the value of $form_data['zipcode'] 
    // Maybe a str_replace of a token, or generate a new email body from a template 

    // Return the modified HTML email body 
    return $message; 
} 

add_filter('ninja_forms_action_email_message', 'custom_email_body_content', 10, 3);