处理联系表格7数据

时间:2015-04-13 15:48:28

标签: wordpress contact-form-7

我正在尝试操作以联系表单7创建的联系表单中发送的数据。
用户选择一个产品,然后设置一个隐藏的文本字段,其中包含所选产品ID的值,已分隔用逗号表示。

我试图将这些ID更改为与产品标题的anhor链接,全部用逗号分隔。

这是我目前的代码:

add_action('wpcf7_before_send_mail', 'my_wpcf7_before_send_mail');
function my_wpcf7_before_send_mail($form) {

    $submission = WPCF7_Submission::get_instance();
    $wpcf7 = WPCF7_ContactForm::get_current();

    if ($submission) {

        $data = $submission->get_posted_data();

        if (empty($data)) {
            return;
        }

        $extras = explode(',', $data['extras']);
        $extras_html = '';

        foreach ($extras as $extra) {

            if ($extra != '') {
                $extras_html .= '<a href="'.get_permalink(preg_replace('/\s+/', '', $extra)).'">'.preg_replace('/\s+/', '', $extra).'</a> ';
            }

        }

        $data['extras'] = $extras_html;

    }

    $wpcf7->set_properties(array(
        'mail' => $data
    ));

}

此刻,表单根本无法发送。 我尝试的所有变体都不会操纵HTML。

0 个答案:

没有答案