当从其他位置提交其他信息时,我该如何从需要的验证码中提交Salesforce

时间:2019-06-18 11:21:46

标签: salesforce recaptcha

从与Recaptcha提交的联系表提交后,我就拥有正常的联系表和销售人员,我已经从字段值中获得了所有联系并转移到销售人员。如果在销售中禁用了Recaptcha,则可以正常工作,但是当我启用销售队伍中所需的Recaptcha时,不会在销售队伍中产生潜在客户。 有什么方法可以提交所需的销售证明表格隐藏方法。或者有什么方法可以从一种形式使用Recptcha到另一种形式?

if(isset($_POST['submitSalesForceForm_test'])) {
 $post_data = $_POST;

    $error_message = '';
    $captcha_settings = sanitize_text_field($post_data['captcha_settings']);
    $first_name = sanitize_text_field($post_data['first_name']);
    $last_name = sanitize_text_field($post_data['last_name']);
    $email = sanitize_email($post_data['email']);
    $company = sanitize_text_field($post_data['company']);
    $phone = sanitize_text_field($post_data['phone']);
    $state_code = sanitize_text_field($post_data['state_code']);
    $description = sanitize_textarea_field($post_data['description']);
    $g_recaptcha_response = sanitize_textarea_field($post_data['g-recaptcha-response']);

    if (empty($first_name) || empty($last_name) || empty($email) || empty($company) || empty($phone) || empty($state_code) || empty($description)):
        $error_message = "Invalid entry";
    endif;

    if(empty($error_message)){
        if ( !is_email( $email ) ) {
            $error_message =  'Email address is invalid.';
        }
    }
    if(empty($error_message)):
        if(empty(trim($g_recaptcha_response))):
            $error_message = "You cannot leave captcha code empty.";
        else:
            $secret = $secret;
            $captcha = $_POST['g-recaptcha-response'];
            $remoteip = $_SERVER['REMOTE_ADDR'];
            $response=json_decode(file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=$secret&response=".$captcha."&remoteip=".$remoteip), true);
            if($response['success'] != 1):
                $error_message = "Verification failed, please try again.";
            endif;
        endif;
    endif;

    if (empty($error_message)) {
        $fields_string = "";
        $url = "https://webto.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8";
        $fields = array(
          'captcha_settings' => '{"keyname":"test","fallback":"true","orgId":"xxxxxxxxxxxx","ts":""}',
            'oid' => 'xxxxxxxxxxxx',
            'retURL' => $returnurl,
            'first_name' => $first_name,
            'last_name' => $last_name,
            'email' => $email,
            'phone' => $phone,
            'state' => $state_code,
            'country' => '$country',
            'company' => $company,
            'description' => $description,
            'g-recaptcha-response' => $g_recaptcha_response,
            'submit' => 'Submit',
        );
        //url-ify the data for the POST
        foreach ($fields as $key => $value) {
            $fields_string .= $key . '=' . $value . '&';
        }
        rtrim($fields_string, '&');


        $curl = curl_init();
        curl_setopt_array($curl, array(
            CURLOPT_URL => $url,
            CURLOPT_POST => count($fields),
            CURLOPT_POSTFIELDS => $fields_string,
        ));
        $response = curl_exec($curl);
        echo $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
        $err = curl_error($curl);
        curl_close($curl);

        if ($err) :
            $error_message =  'Error curl. Please try again';
        elseif ($status == 200 || $status == 400):
            $result = json_decode($response, true); //because of true, it's in an array
            wp_redirect( $returnurl);
            exit;
        else:
            $error_message = 'Error please try again';
        endif;
    }


    if (!empty($error_message)) {
        ?>
        <script>
            jQuery(document).ready(function () {
                var scroll_hight_sales_form_error_msg = jQuery('.main-menu-wrapper').outerHeight()
                jQuery('html, body').animate({
                    scrollTop: jQuery('.sales-form-error-msg').offset().top - scroll_hight_sales_form_error_msg
                }, 'slow');
            });
        </script>
        <?php
        echo '<div class="sales-form-error-msg" style="color: #f30027">';
        echo $error_message;
        echo '</div>';
    }

}

?>
<form action="#" method="POST">

    <label for="first_name" class="sr-only">First Name</label>
    <input id="first_name" maxlength="40" name="first_name" size="20" type="text" placeholder="First Name*" required value="<?php if(isset($first_name)){ echo $first_name;}  ?>" />

    <label for="last_name" class="sr-only">Last Name</label>
    <input id="last_name" maxlength="80" name="last_name" size="20" type="text" placeholder="Last Name*" required value="<?php if(isset($last_name)){ echo $last_name; } ?>"/>

    <label for="email" class="sr-only">Email</label>
    <input id="email" maxlength="80" name="email" size="20" type="email" placeholder="Email*" required value="<?php if(isset($email)){ echo $email; } ?>"/>

    <label for="phone" class="sr-only">Phone</label>
    <input id="phone" maxlength="40" name="phone" size="20" type="text"  placeholder="Phone*" required value="<?php if(isset($phone)){ echo $phone;} ?>"/>

    <label for="state_code" class="sr-only">State/Province</label>
    <select id="state_code" name="state_code" class="input-select" required>
        <option value="">Select State*</option>
        <?php foreach ($state_name_array as $key => $value): ?>
            <option value="<?php echo $key; ?>" <?php if($key == $state_code) echo "selected"; ?>><?php echo $value; ?></option>
        <?php endforeach; ?>
    </select>


    <label for="company" class="sr-only">Company</label>
    <input id="company" maxlength="40" name="company" size="20" type="text" placeholder="Employer*" required value="<?php if(isset($company)){ echo $company;} ?>"/>

    <label for="description" class="sr-only">Description</label>
    <textarea name="description" placeholder="Message*" required><?php if(isset($description)){ echo $description;} ?></textarea>
    <br>
    <div class="g-recaptcha" data-sitekey="<?php echo $sitekey;?>"></div>
    <input name="submitSalesForceForm_test" type="submit" />

</form>
<script src="https://www.google.com/recaptcha/api.js" async defer></script>

0 个答案:

没有答案