2010-04-02 43 views
0

我有大約6個子域名有「聯繫我們」鏈接,我將所有這些鏈接發送到使用「聯繫表單」 7" 。我將?from = site-name添加到每個鏈接,以便我可以在聯繫人表單中設置$ referencedFrom變量。黑客「聯繫表單7」代碼添加「推薦人」字段

我唯一缺少的兩件事是:(1)能夠將這個referencedFrom變量插入到我有人提交表單時得到的電子郵件中;(2)將用戶重定向到他們來的網站的能力from(存於$ referFrom)

有沒有想法?

下面是一些代碼從包括,我認爲可能是電子郵件插件的一部分,但它沒有做多少/ classes.php ...

function mail() { 
    global $referrer; 
    $refferedfrom = $referrer; //HERE IS MY CUSTOM CODE 
    $fes = $this->form_scan_shortcode(); 

    foreach ($fes as $fe) { 
     $name = $fe['name']; 
     $pipes = $fe['pipes']; 

     if (empty($name)) 
      continue; 

     $value = $_POST[$name]; 

     if (WPCF7_USE_PIPE && is_a($pipes, 'WPCF7_Pipes') && ! $pipes->zero()) { 
      if (is_array($value)) { 
       $new_value = array(); 
       foreach ($value as $v) { 
        $new_value[] = $pipes->do_pipe($v); 
       } 
       $value = $new_value; 
      } else { 
       $value = $pipes->do_pipe($value); 
      } 
     } 

     $this->posted_data[$name] = $value; 
     $this->posted_data[$refferedfrom] = $referrer; //HERE IS MY CUSTOM CODE 
    } 

我還以爲我能插referredFrom代碼某處此功能,以及...

function compose_and_send_mail($mail_template) { 
    $regex = '/\[\s*([a-zA-Z][0-9a-zA-Z:._-]*)\s*\]/'; 
    $callback = array(&$this, 'mail_callback'); 

    $mail_subject = preg_replace_callback($regex, $callback, $mail_template['subject']); 
    $mail_sender = preg_replace_callback($regex, $callback, $mail_template['sender']); 
    $mail_body = preg_replace_callback($regex, $callback, $mail_template['body']); 
    $mail_recipient = preg_replace_callback($regex, $callback, $mail_template['recipient']); 

    $mail_headers = "From: $mail_sender\n"; 

    if ($mail_template['use_html']) 
     $mail_headers .= "Content-Type: text/html\n"; 

    $mail_additional_headers = preg_replace_callback($regex, $callback, 
     $mail_template['additional_headers']); 
    $mail_headers .= trim($mail_additional_headers) . "\n"; 

    if ($this->uploaded_files) { 
     $for_this_mail = array(); 
     foreach ($this->uploaded_files as $name => $path) { 
      if (false === strpos($mail_template['attachments'], "[${name}]")) 
       continue; 
      $for_this_mail[] = $path; 
     } 

     return @wp_mail($mail_recipient, $mail_subject, $mail_body, $mail_headers, 
      $for_this_mail); 
    } else { 
     return @wp_mail($mail_recipient, $mail_subject, $mail_body, $mail_headers); 
    } 
} 

回答

0

首先,爲了獲得從變量,你必須插入

$referrer = $_GET['from'];

頂部腳本中的某處,至少在插入的最後一行之前。

此外,在第二個腳本中,您必須以某種方式將值添加到$ mail_body,但由於我不知道該值是如何構成的,所以我無法幫助解決這個問題。 這個表單的代碼是否可以在線使用?

+0

http://wordpress.org/extend/plugins/contact-form-7/ – 2010-04-05 11:31:02

0

插入到您的functions.php或創建一個簡單的插件...

function custom_wpcf7_special_mail_tag($output, $name ) { 
    if ('from' == $name) { 
     $referredFrom = (isset($_GET["from"]) && !empty($_GET["from"])) ? $_GET["from"] : ''; 
     $output = $referredFrom; 
    } 

    return $output; 
} 
add_filter('wpcf7_special_mail_tags', 'custom_wpcf7_special_mail_tag', 10, 2); 

使用[from]標籤在你的郵件模板。

2.

function add_custom_js_cf7() { 
    $referredFrom = (isset($_GET["from"]) && !empty($_GET["from"])) ? $_GET["from"] : ''; 
    if ($referredFrom) { 
    ?> 
     <script type="text/javascript"> 
     var from = "<?php echo $referredFrom; ?>"; 
     </script> 
<?php } 
} 
add_action('wpcf7_enqueue_scripts', 'add_custom_js_cf7'); 

而且在你的表格設置中添加此行的 「其他設置」:

on_sent_ok: "location = from;" 

http://contactform7.com/blog/2010/03/27/redirecting-to-another-url-after-submissions/


您還可以使用global $referredFrom;如果你宣佈如此mewhere。