'Auto email response after enquiry form not working, 'emailid' argument undefined?

I need to add auto response email on my forms.

This requires us to add an argument to the [cd-iframe] directive specifying which email needs to be sent. This allows us to control different email templates on different pages and websites.

I have been trying to modify the CD-CRM plugin on WordPress to allow this new argument (called “emailid”) and pass it onto ASP (where the email will actually go out). Unfortunately, I have been getting limited success.

I have been using http://www.royalliverbuildingvenue.co.uk/contact/ as my test page, taking great care to back everything up before making changes.

Here is the code:

cd-crm-integration-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);
    });

});

The plugin now creates an “&emailid=” argument in the address but the value is always “undefined” (which sounds like JS to me).

I hope you can help and look forward to hearing from you.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source