Web forms are a key means of collecting information about potential leads. Having the options of a web form integrated into a CRM allows you to automate the capture of data, such as names, addresses, emails and phone numbers directed to the CRM database.

The integration of web forms with a CRM means better audience segmentation, allowing companies to personalize their communications and offer better experiences for customers.

Through the open API interface in Megacall it is possible to connect the CRM for free on any communication channel. Below, is an example of a functional form to accept requests or comments and create leads.

Note that the form is simplified and we recommend modifying it for use on your website, defining your own style and adding necessary measures such as captcha.

The form is in HTML, the elements and libraries are inserted into the website code. For the correct functioning of the form, it will be necessary to add the PHP script to add the data in Megacall CRM.

Code configuration phases: Creation of leads in the CRM from the web form.

  1. If you are not registered in the Megacall CRM, the first step is to create and activate the platform. The user must be created and activated in the CRM, otherwise it is not possible to continue.
  2. From the personal area, we can obtain the API key.
  3. Accessing https://my.site.com/megacall_leads we create a script that will be used to send data from the form to the CRM through API. In UserKey and Secret, we must indicate the key and password obtained in the second step.
    <?php
    $postData = $_POST;
    if ($postData) {
     if (isset($postData['phones'], $postData['phones'][0], $postData['phones'][0]['phone'])) {
     $postData['phones'][0]['type'] = 'work';
     }
     if (isset($postData['contacts'], $postData['contacts'][0], $postData['contacts'][0]['value'])) {
     $postData['contacts'][0]['type'] = 'email_work';
     }
     $params = ['lead' => $postData];
     $params['lead']['lead_source'] = 'form';
     $leadData = makePostRequest('/v1/zcrm/leads', $params);
     if (isset($leadData['status'], $leadData['data'], $leadData['data']['id'])
     && $leadData['status'] === 'success'
     && (isset($postData['comment']) && !empty($postData['comment']))
     ) {
     //If the client has been created, we will leave a text note in the activity stream
     $addFeedMethod = sprintf('/v1/zcrm/customers/%s/feed', $leadData['data']['id']);
     $messageData = ['content' => $postData['comment']];
     makePostRequest($addFeedMethod, $messageData);
     }
     var_dump($leadData);
    }
    exit();
    function makePostRequest($method, $params)
    {
     // userKey and secret with the ones obtained in your personal area
     $userKey = '';
     $secret = '';
     $apiUrl = 'https://api.megacall.es';
     ksort($params);
     $paramsStr = makeParamsStr($params);
     $sign = makeSign($paramsStr, $method, $secret);
     $curl = curl_init();
     curl_setopt($curl, CURLOPT_URL, $apiUrl . $method);
     curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
     curl_setopt($curl, CURLOPT_POST, true);
     curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
     curl_setopt($curl, CURLOPT_POSTFIELDS, $paramsStr);
     curl_setopt($curl, CURLOPT_HTTPHEADER, [
     'Authorization: ' . $userKey . ':' . $sign
     ]);
     $response = curl_exec($curl);
     $error = curl_error($curl);
     curl_close($curl);
     if ($error) {
     return null;
     } else {
     return json_decode($response, true);
     }
    }
    /**
    * @param array $params
    * @return string
    */
    function makeParamsStr($params)
    {
     return http_build_query($params, null, '&', PHP_QUERY_RFC1738);
    }
    /**
    * @param string $paramsStr
    * @param string $method
    * @param string $secret
    *
    * @return string
    */
    function makeSign($paramsStr, $method, $secret)
    {
     return base64_encode(
     hash_hmac(
     'sha1',
     $method . $paramsStr . md5($paramsStr),
     $secret
     )
     );
    }
  4. In the website code we are going to add the form to obtain and send the lead in API where the hidden fields are mandatory for the request.
    <form method="POST" action="/zcrm_leads">
     <label for="name">Name:
     <br>
     <input type="text" id="name" name="name" value="">
     <br>
     <label for="comment">Comment:</label><br>
     <input type="text" id="comment" name="comment" value="">
     <br>
     <label for="phone">Phone:</label><br>
     <input type="text" id="phone" name="phones[0][phone]" value="">
     <br>
     <label for="phone">Email:</label><br>
     <input type="text" id="email" name="contacts[0][value]" value="">
     <br>
     <br>
     <input type="submit" value="Submit">
    </form>
  5. After these steps, the form will be configured and ready to work. By not having a design it will appear like this:forma para captar leads en crm

Finally, we remember to define your own style and add protection such as the free reCAPTCHA. It is possible to update the form in any way, whether it is a script for other data or for another section (contact, tasks). To know all the integration methods, you can see the full list at Megacall CRM API.