我需要在表单上添加自动回复电子邮件。
这要求我们在[cd-iframe]指令中添加一个参数,指定需要发送哪个电子邮件。这使我们可以控制不同页面和网站上的不同电子邮件模板。
我一直在尝试修改WordPress上的CD-CRM插件,以允许这个新参数(称为“emailid”)并将其传递给ASP(电子邮件实际将在那里发布)。不幸的是,我的成功有限。
我一直在使用http://www.royalliverbuildingvenue.co.uk/contact/作为我的测试页面,在进行更改之前要非常小心地备份所有内容。
以下是代码:
CD-CRM集成-ea.php
<?php
// If this file is called directly, abort.
if (!defined('WPINC')) {
die;
}
function my_scripts() {
wp_register_script('analytics-cookie', plugins_url('/analytics-cookie.js', __FILE__), array('jquery'), 1.0, true);
wp_register_style( 'cd-style', plugins_url('style.css', __FILE__) );
wp_enqueue_style( 'cd-style' );
wp_enqueue_script('analytics-cookie');
}
add_action( 'wp_enqueue_scripts', 'my_scripts' );
function cd_iframe_shortcode($atts)
{
//Default values
extract(shortcode_atts(array(
'url' => 'https://secure.concertogroup.co.uk/forms/enquiry/vs.asp',
'style' => 'width:100%;height:500px;',
'stylesheet' => '',
'pass_venue' => 0,
'colour' => 0,
'forecolour' => 0,
'id' => 1,
'thank_you' => 0,
'subject' => 0,
'emailid' => 0
), $atts));
$refUrl = "{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
$escaped_url = htmlspecialchars($refUrl, ENT_QUOTES, 'UTF-8');
$escaped_url = strtok($escaped_url, '?');
$ref = $escaped_url;
$prefix = $id;
$iframeDiv = '<div id="iframeParent-'. $prefix .'" class="iframe-parent" data-id="'. $prefix .'"></div>';
pw_load_scripts($ref, $url, $style, $stylesheet, $pass_venue, $colour, $forecolour, $id, $thank_you, $subject, $emailid);
return $iframeDiv;
}
function pw_load_scripts($ref, $url, $style, $stylesheet, $pass_venue, $colour, $forecolour, $id, $thank_you, $subject, $emailid)
{
wp_register_script('pw-script', plugins_url('/script.js', __FILE__), array('jquery'), 1.2, true);
wp_enqueue_script('pw-script');
wp_localize_script('pw-script', 'pw_script_vars' . $id, array(
'ref' => $ref,
'url' => $url,
'cssStyle' => $style,
'stylesheet' => $stylesheet,
'pass_venue' => $pass_venue,
'colour' => $colour,
'forecolour' => $forecolour,
'id' => $id,
'thank_you' => $thank_you,
'subject' => $subject,
'emailid' => $emailid
)
);
}
// Launch the plugin
add_shortcode('cd_iframe', 'cd_iframe_shortcode');
的script.js
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
function convertToSlug(Text) {
if (Text !== '') {
return Text
.toLowerCase()
.replace(/[^\w ]+/g,'')
.replace(/ +/g,'-')
;
} else {
return '';
}
}
function cdReturnIFrame(prefix) {
var cookieValue = readCookie('first.session');
var settingObj = window["pw_script_vars" + prefix];
var venueName = '';
var iframeUrl = settingObj.url + '?ref=' + settingObj.ref + '&stylesheet=' + settingObj.stylesheet + '&' + cookieValue;
if (settingObj.pass_venue === "1") {
venueName = jQuery( "#venue-title" ).text();
venueName = convertToSlug(venueName);
iframeUrl = iframeUrl + '&subject=' + venueName;
}
if (settingObj.thank_you !== "0") {
iframeUrl = iframeUrl + '&thank_you=' + settingObj.thank_you;
}
if (settingObj.subject !== "0") {
iframeUrl = iframeUrl + '&subject=' + settingObj.subject;
}
if (settingObj.colour !== "0") {
iframeUrl = iframeUrl + '&colour=' + settingObj.colour;
}
if (settingObj.forecolour !== "0") {
iframeUrl = iframeUrl + '&forecolour=' + settingObj.forecolour;
}
if (settingObj.emailid !== "0") {
iframeUrl = iframeUrl + '&emailid=' + settingObj.emailid;
}
// Define
var iframe = '<div class="iframe-container"><iframe allowfullscreen class="crm_form" frameborder="0" src=' + iframeUrl + ' style=' + settingObj.cssStyle + '></iframe></div>';
jQuery('#iframeParent-' + prefix).append(iframe);
}
jQuery(document).ready(function($) {
$('.iframe-parent').each(function( index ) {
var id = $(this).data('id');
cdReturnIFrame(id);
});
})
;
该插件现在在地址中创建了一个“&amp; emailid =”参数,但该值始终为“未定义”(对我来说听起来像JS)。
我希望你能提供帮助,并期待收到你的回复。