1

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

例子:

用户填写该zipcode字段,我不想将数据添加到最近商店的邮件正文中。

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

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

4

1 回答 1

5

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

过滤器具有三个参数:

  1. $message这是当前电子邮件正文的 (HTML) 字符串
  2. $data表单数据(包括有关表单和用户提交的数据)
  3. $action_settings发送电子邮件的参数(到地址等)

例子:

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);
于 2017-01-19T22:45:55.623 回答