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


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

Example: Simple newsletter sign-up form

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

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

Sending data to Mailocator

function subscribe(){
   var data = {}; = 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



Mailnatives, s.r.o. with IČO 07891768 is registered at the Regional Court in Hradec Králové under the file number C 43368