Now that you have created a form on your Dashboard, you will need to understand how to collect and use the data filled out by your readers.

👉 If you are looking for more information about form creation, you can read our article How do I create a form and use it in a scenario?

For security reasons, the data collected in the forms is not saved but sent in a Javascript event. To retrieve the data from each form, it is necessary to implement the collection technically.

Use the available event "formSubmit"

It is up to you to integrate the safe-keeping and sending of data. However, this is easy to do thanks to a system on our SDK.

Here is how the event will work (be sure to read the comments added in the data).

📌 Poool script - previous version (poool Legacy)

poool('event', 'onFormSubmit', function(event) {
console.log('Form ' + event.name + ' sent!');

// If needed, you can review all the fields to apply your own checks.
// If an array including the invalid fields ids is returned, the paywall will show a list of the invalid fields.
// If the array returned is empty or nothing is returned, the article will be unlocked.

var invalid = [];

if (event.fields.password !== event.fields.passwordRepeat) {
invalid.push('password');
invalid.push('passwordRepeat');
}

return invalid;
});

For more information, do not hesitate to check our technical documentation about onFormSubmit event.

📌 Poool script - new version

access.on('formSubmit', event => {
console.log('Form ' + event.name + ' sent!');

// If needed, you can review all the fields to apply your own checks.
// If an array including the invalid fields ids is returned, the paywall will show a list of the invalid fields.
// If the array returned is empty or nothing is returned, the article will be unlocked.

var invalid = [];

if (event.fields.password !== event.fields.passwordRepeat) {
invalid.push('password');
invalid.push('passwordRepeat');
}

// You can also return your own custom error messages

if (!events.fields.address) {
invalid.push({ fieldKey: 'address', message: 'Your address is empty. Please fill it.'});
}
if (invalid.length) {
return invalid;
}
});

For more information, do not hesitate to check our technical documentation about formSubmit event.

Event "formSubmit" specificities

As you can see, this event functions according to 2 principles:

  • The 'event' argument

  • The 'invalid' data

The 'event' argument will contain all user values. The answers correspond to each variable name which you will have entered when you created the form.

In these fields, we check the format of the email address and the date.

For the others, you can create your own event sequence and send the 'invalid' message whenever there are any errors in order to ask the user to correct what they have just entered.

If you have any questions, please don't hesitate to contact us via the Intercom messenger!

Did this answer your question?