Přejít k obsahu  Přejít k hlavnímu menu

Blog / Knowledge base

Updated: 8. March 2021

Processing of the form (campaign) inserted into the page

How to send data to Mailocator from a form located on your site?

In cases where you need to insert a form into your pages and process it with Mailocator, the following solution is suitable, with which you can not only simply transfer data to ESP but also use simple javascript to handle the result of data processing (duplications, invalid entries, acknowledgments).

an easy way to submit a newsletter subscription from your own web form without having to call an API
the possibility of handling the results of validation and sending data
processing and transmission of data directly to the ESP
processing of questionnaires and other campaigns


Snippet placement


<script>
(function(e,a,d,b,c){a.mlctr={p:"https://app.mailocator.com",cpg:"12345************"};
b=a.createElement(d);c=a.getElementsByTagName(d)[0];b.async=1;
b.src=a.mlctr.p+"/_/s/"+a.mlctr.cpg+"/ml.js";
c.parentNode.insertBefore(b,c)})(window,document,"script");
</script>



Make sure you have a snippet for your Mailocator project on your site.

Example: Simple newsletter sign-up form


<h1>Email static subscription</h1>
<form>
    <input type="text" name="email" value="" id="email_address" size="50" />
    <button onclick="subscribe()">subscribe</button>
</form>


The minimum request is the email field and the event that the form submits.


Sending data to Mailocator


function subscribe(){
   var data = {};
   data.email = document.getElementById('email_address').value;
   mailocator.action.subscribe( data, callback );
}


You can send data directly using the Mailocator action mailocator.action.subscribe or a custom function to add (hidden) data and pass the name of the function you wish to call after processing - callback ().

object data must contain at least the "email" property, other properties can be used as custom/system fields of your ESP
the data and the name of the function (callback) are sent, which is to be called and serviced after the completion of the process on the part of Mailocator

Sending data to Mailocator


function callback( result ){
   var status = Number( result.status );
   switch( status ){
       case 1 : { /* subscribed successfully */ break;}
       case 0 : { /* contact already subscribed */ break;}
       case -1 : { /* email syntax error */ break; }
       case -2 : { /* invalid email - AddressCheck not passed */ break; }
       case -99: { /* system error */ break; }
   }
}


If you have passed a return processing function to Mailocator (in this case callback), this function is called after Mailocator processes the data. As an argument, the function receives an object that includes the status property, which can be easily used to handle the result:

1 ... the data was processed without error
0 ... the contact email already exists in the database
-1 ... bad email syntax
-2 ... invalid email (typo, invalid domain, etc.)
-99 ... another error


RELATED

Switching between integrations within the same project

If you need to route some campaigns to the CRM, others to an email tool, and store the results from surveys in an independent database, this solution is also easy to set up.

Automated values, adding values to hidden inputs

Merging of arbitrary fields and automatic filling of selected fields with a series of system values

Launch a campaign when you hover or touch a specific location on the page

Mark a location that triggers a campaign when the user hovers over it or touches it on a touch device

Mailocator Events

With events, you can intelligently manage the sequence of campaigns across the entire workflow scenario and display much more relevant and precisely targeted content in real time.

Notification

Set up the display of notifications on your site using Mailocator