S
S
stichii2016-11-18 17:47:16
Bitrix24
stichii, 2016-11-18 17:47:16

How to display a message about the successful sending of Contact form data in Bitrix24?

Good afternoon! The site is on WordPress and it was necessary to make sure that the contact form 7 data, when sent, got into Bitrix 24 in the form of a new lead and sent to the mail. The rest.php file was created for this.

<?
// CRM server conection data
define('CRM_HOST', '111.bitrix24.ru'); // your CRM domain name
define('CRM_PORT', '443'); // CRM server port
define('CRM_PATH', '/crm/configs/import/lead.php'); // CRM server REST service path

// CRM server authorization data
define('CRM_LOGIN', '[email protected]'); // login of a CRM user able to manage leads
define('CRM_PASSWORD', '111'); // password of a CRM user
// OR you can send special authorization hash which is sent by server after first successful connection with login and password
//define('CRM_AUTH', 'e54ec19f0c5f092ea11145b80f465e1a'); // authorization hash

/********************************************************************************************/

// POST processing
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
  $leadData = $_POST['DATA'];

  // get lead data from the form
  $postData = array(
    'TITLE' => $leadData['TITLE'],
    'NAME' => $_POST['name-413'],
    'PHONE_MOBILE' => $_POST['tel-213'],
    'EMAIL_WORK' => $_POST['email-313'],
    'UF_CRM_1476713952' => $_POST['number-695'],
    'UF_CRM_1476707952' => $_POST['date-478'],
    'UF_CRM_1476714173' => $_POST['name-415'],
    'UF_CRM_1476714222' =>$_POST['textarea-113'],
  );

  // append authorization data
  if (defined('CRM_AUTH'))
  {
    $postData['AUTH'] = CRM_AUTH;
  }
  else
  {
    $postData['LOGIN'] = CRM_LOGIN;
    $postData['PASSWORD'] = CRM_PASSWORD;
  }

  // open socket to CRM
  $fp = fsockopen("ssl://".CRM_HOST, CRM_PORT, $errno, $errstr, 30);
  if ($fp)
  {
    // prepare POST data
    $strPostData = '';
    foreach ($postData as $key => $value)
      $strPostData .= ($strPostData == '' ? '' : '&').$key.'='.urlencode($value);

    // prepare POST headers
    $str = "POST ".CRM_PATH." HTTP/1.0\r\n";
    $str .= "Host: ".CRM_HOST."\r\n";
    $str .= "Content-Type: application/x-www-form-urlencoded\r\n";
    $str .= "Content-Length: ".strlen($strPostData)."\r\n";
    $str .= "Connection: close\r\n\r\n";

    $str .= $strPostData;

    // send POST to CRM
    fwrite($fp, $str);

    // get CRM headers
    $result = '';
    while (!feof($fp))
    {
      $result .= fgets($fp, 128);
    }
    fclose($fp);

    // cut response headers
    $response = explode("\r\n\r\n", $result);

    $output = '<pre>'.print_r($response[1], 1).'</pre>';
  }
  else
  {
    echo 'Connection Failed! '.$errstr.' ('.$errno.')';
  }
}
else
{
  $output = '';
}

// HTML form
?>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<?=$output;?>
<form action="rest.php" method="post">
  Title*: <input type="text" name="DATA[TITLE]" value="" /><br />
  Company Name: <input type="text" name="DATA[COMPANY_TITLE]" value="" /><br />
  First Name: <input type="text" name="DATA[NAME]" value="" /><br />
  Last Name: <input type="text" name="DATA[LAST_NAME]" value="" /><br />
  Comments: <textarea name="DATA[COMMENTS]"></textarea><br />
  <input type="submit" value="Send" />
</form>

and hook for contact forms
function before($wpcf7){
   $submission = WPCF7_Submission::get_instance();
   $form = WPCF7_ContactForm::get_current();
    $props = $form->get_properties();
    // Bitrix24
    include_once( get_stylesheet_directory() . '/rest.php' );


}
add_action("wpcf7_before_send_mail", "before");

The data from the form gets into Bitrix24 in the form of a new lead. But on the site after pressing the "Submit" button, a loader (spinning arrows) appears next to the button and there is no text about successful sending. Do not tell me how to fix this so that after sending a text appears about the successful sending of data? Before the hook, the text about successful sending after sending the data to the mail was.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
George N, 2016-11-18
@promconsulting

Install the Bitrix24 CRM form and don't bother

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question