How do I retrieve data from a form?

Collecting data from a form is simpler than it seems!

Madeleine White avatar
Écrit par Madeleine White
Mis à jour il y a plus d’une semaine

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. 

As you will have read in our article about how to create a form, we don't save any data from the forms on our server. 

It is therefore 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('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;
});

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

  1. The 'event' argument

  2. 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 only check a few things, such as verifying 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. 

You can access the documentation by clicking here

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

 

Avez-vous trouvé la réponse à votre question ?