示例#1
0
function submit_salesforce_form($post, $options)
{
    global $wp_version;
    $form_id = absint($_POST['form_id']);
    $org_id = salesforce_get_option('org_id', $form_id, $options);
    //echo '$org_id='.$org_id;
    if (!$org_id) {
        $org_id = $options['org_id'];
    }
    // fallback to global
    if (!$org_id) {
        error_log("Salesforce: No SalesForce Organization ID set.");
        return false;
    }
    //spam honeypot
    if (!empty($_POST['message'])) {
        error_log("Salesforce: No message set.");
        return false;
    }
    //print_r($_POST); //DEBUG
    //echo $org_id;
    $post['oid'] = $org_id;
    // web to lead
    $post['orgid'] = $org_id;
    // web to case
    if (!isset($post['lead_source'])) {
        if (!empty($options['forms'][$form_id]['source'])) {
            $post['lead_source'] = str_replace('%URL%', '[' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'] . ']', $options['forms'][$form_id]['source']);
        }
    }
    $post['lead_source'] = apply_filters('salesforce_w2l_lead_source', $post['lead_source'], $form_id);
    //$post['debug']	= 0;
    /*
    	$body = '';
    
    	foreach( $post as $k => $v ){
    		if( is_array( $v ) ){
    			foreach( $v as $i ){
    				$body .= '&'.urlencode($k).'='.urlencode($i);
    			}
    		}else{
    			$body .= '&'.urlencode($k).'='. urlencode($v);
    
    		}
    	}
    
    	$body = substr( $body, 1 );
    */
    $form_type = $options['forms'][$form_id]['type'];
    // Filter arguments before generating POST to SF
    $post = apply_filters('salesforce_w2l_post_data', $post, $form_id, $form_type);
    $body = preg_replace('/%5B[0-9]+%5D/simU', '', http_build_query($post));
    // remove php style arrays for array values [1]
    //echo $body .'<hr>';
    $sslverify = false;
    // setting to override
    if (!empty($options['sslverify'])) {
        $sslverify = (bool) $options['sslverify'];
    }
    // Set SSL verify to false because of server issues, unless setting is set... a filter can also be used to override arguments
    $args = array('body' => $body, 'headers' => array('Content-Type' => 'application/x-www-form-urlencoded', 'user-agent' => 'WordPress-to-Lead for Salesforce plugin - WordPress/' . $wp_version . '; ' . get_bloginfo('url')), 'sslverify' => $sslverify);
    $args = apply_filters('salesforce_w2l_post_args', $args);
    if ($form_type == 'case') {
        $url = 'https://www.salesforce.com/servlet/servlet.WebToCase?encoding=UTF-8';
    } else {
        $url = 'https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8';
    }
    // Do we need to change the URL we're submitting to?
    $url = apply_filters('salesforce_w2l_api_url', $url, $form_type, $post);
    // Pre submit actions
    do_action('salesforce_w2l_before_submit', $post, $form_id, $form_type);
    $result = wp_remote_post($url, $args);
    // Test broken submit
    //$result = new WP_Error( 'broke', __( "I've fallen and can't get up", "my_textdomain" ) );
    if (is_wp_error($result)) {
        error_log("Salesforce HTTP error: " . print_r($result, true));
        do_action('salesforce_w2l_error_submit', $result, $post, $form_id, $form_type);
        $subject = __('Salesforce Web to %%type%% Error', 'salesforce');
        $append = print_r($result, 1);
        salesforce_cc_admin($post, $options, $form_id, $subject, $append);
        return false;
    }
    if ($result['response']['code'] == 200) {
        // Post submit actions
        do_action('salesforce_w2l_after_submit', $post, $form_id, $form_type);
        unset($_POST['oid']);
        unset($_POST['org_id']);
        if (isset($_POST['w2lcc']) && $_POST['w2lcc'] == 1) {
            salesforce_cc_user($post, $options, $form_id);
        }
        salesforce_cc_admin($post, $options, $form_id);
        // Prevent multiple form submissions by clearing key data
        unset($_POST['form_id']);
        unset($_POST['w2lsubmit']);
        return true;
    } else {
        error_log("Salesforce response error: " . print_r($result, true));
        return false;
    }
}
示例#2
0
function submit_salesforce_form($post, $options)
{
    global $wp_version;
    $form_id = absint($_POST['form_id']);
    $org_id = salesforce_get_option('org_id', $form_id, $options);
    //echo '$org_id='.$org_id;
    if (!$org_id) {
        $org_id = $options['org_id'];
    }
    // fallback to global
    if (!$org_id) {
        error_log("Salesforce: No SalesForce Organization ID set.");
        return false;
    }
    //spam honeypot
    if (!empty($_POST['message'])) {
        error_log("Salesforce: No message set.");
        return false;
    }
    //print_r($_POST); //DEBUG
    //echo $org_id;
    $post['oid'] = $org_id;
    // web to lead
    $post['orgid'] = $org_id;
    // web to case
    if (!empty($options['forms'][$form_id]['source'])) {
        $post['lead_source'] = str_replace('%URL%', '[' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'] . ']', $options['forms'][$form_id]['source']);
    }
    $post['debug'] = 0;
    // Set SSL verify to false because of server issues.
    $args = array('body' => $post, 'headers' => array('user-agent' => 'WordPress-to-Lead for Salesforce plugin - WordPress/' . $wp_version . '; ' . get_bloginfo('url')), 'sslverify' => false);
    $form_type = $options['forms'][$form_id]['type'];
    if ($form_type == 'case') {
        $url = 'https://www.salesforce.com/servlet/servlet.WebToCase?encoding=UTF-8';
    } else {
        $url = 'https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8';
    }
    $url = apply_filters('salesforce_w2l_api_url', $url, $form_type);
    $result = wp_remote_post($url, $args);
    if (is_wp_error($result)) {
        error_log("Salesforce HTTP error: " . print_r($result, true));
        return false;
    }
    if ($result['response']['code'] == 200) {
        unset($_POST['oid']);
        unset($_POST['org_id']);
        if (isset($_POST['w2lcc']) && $_POST['w2lcc'] == 1) {
            salesforce_cc_user($post, $options, $form_id);
        }
        if (isset($options['ccadmin']) && $options['ccadmin']) {
            salesforce_cc_admin($post, $options, $form_id);
        }
        // Prevent multiple form submissions by clearing key data
        unset($_POST['form_id']);
        unset($_POST['w2lsubmit']);
        return true;
    } else {
        error_log("Salesforce response error: " . print_r($result, true));
        return false;
    }
}