0

我正在使用 API 将表单数据提交到第三方 CRM 数据库。

这是表单的html...

        <div class="column last">
          <label for="role">What is your role?</label>
          <select name="role" id="role">
            <option value="noresponse">Please select one</option>
            <option value="reseller">Reseller</option>
            <option value="researcher">Researcher</option>
            <option value="end-user">End-user</option>
            <option value="other">Other</option>
          </select>
        </div>

这是使用 API 发送所选字段数据的 php。

<?php
    //Process a new form submission in HubSpot in order to create a new Contact.
    $hubspotutk = $_COOKIE['hubspotutk'];  //grab the cookie from the visitors browser.
    $ip_addr = $_SERVER['REMOTE_ADDR'];  //IP address too.
    $hs_context = array(
            'hutk' => $hubspotutk,
            'ipAddress' => $ip_addr,
            'pageUrl' => 'http://www.suntechmed.com/index.php?option=com_chronoforms&chronoform=test_form',
            'pageName' => 'Test Form'
        );

    $hs_context_json = json_encode($hs_context);
    //Need to populate these varilables with values from the form.
    $str_post = "firstname=" . urlencode($_POST["firstname"])
                        . "&lastname=" . urlencode($_POST["lastname"])
                        . "&company=" . urlencode($_POST["company"])
            . "&role=" . urlencode($POST["role"])            
            . "&address=" . urlencode($_POST["address"])
            . "&city=" . urlencode($_POST["city"])
            . "&state=" . urlencode($_POST["state"])
            . "&zip=" . urlencode($_POST["zip"])
            . "&email=" . urlencode($_POST["email"])
                        . "&hs_context=" . urlencode($hs_context_json);  //Leave this one be :)'

     //replace the values in this URL with your portal ID and your form GUID
    $endpoint = 'https://forms.hubspot.com/uploads/form/v2/myHubspotID/b9752739-c9a3-4dc3-bf34-cb23679a41d4';
    $ch = @curl_init();
    @curl_setopt($ch, CURLOPT_POST, true);
    @curl_setopt($ch, CURLOPT_POSTFIELDS, $str_post);
    @curl_setopt($ch, CURLOPT_URL, $endpoint);
    @curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
    @curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response = @curl_exec($ch);  //Log the response from HubSpot as needed.
    @curl_close($ch);
    echo $response;
    ?>

作为简单文本字段的字段可以很好地进行转换。

我遇到的问题是具有选择选项的字段(如“角色”)没有进入数据库。

事实上,它甚至没有将角色显示为一个空字段。

如果有人有任何建议,那就太好了!

4

1 回答 1

1

创建一个发送在 php 上编写有自己的 API,您可以通过执行以下操作添加用户:

($donation->subscribe_to_newsletter === true) { require_once('system/cm/csrest_subscribers.php');

    $wrap = new CS_REST_Subscribers(CS_REST_DONATE_LIST_ID, CS_REST_DONATE_API_KEY);
    $result = $wrap->add(array(
        'EmailAddress' => $donation->email,
        'Name' => sprintf('%s %s', $donation->first_name, $donation->last_name),
        'CustomFields' => array(),
        'Resubscribe' => true
    ));

你可以在他们的github上找到所有的 php 文件,甚至一些例子

于 2014-01-13T06:47:34.027 回答