Processing of the form (campaign) inserted into the page
How to send data to Mailocator from a form located on your site?
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>
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>
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 );
}
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; }
}
}
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