All Collections
To go further with your settings
Set up fields
Fill a hidden form field with a dynamic value contained in the url
Fill a hidden form field with a dynamic value contained in the url

This article presents the various options for dynamically populating a hidden field on your form.

Florent avatar
Written by Florent
Updated over a week ago

Prerequisites :

  • To create your form template, it's over here!

  • To simply hide a field with a "fixed" value in a form and follow the info retrieval steps, see this article.

  • Some knowledge of Javascript ;-)

⚠️ This article does not describe a Plezi feature, but a "workaround" for the more resourceful among you. The code below is an example that does not take into account everyone's specificities.
>> So it's up to your Dev team to do the config. Ours is an expert in our product, not its link to your website 🤓

❗️Attention, with hidden fields are a configuration of your Plezi that is specific to you. With Plezi updates, the configuration of your hidden fields may be impacted. Be sure to check that your configuration is working properly after updates.

1. If you want to modify the value of a form field on your website

> not integrated into a Plezi landing page (otherwise see next section):


The easiest way to pass a dynamic value in a hidden field is to call the Plezi script in javascript rather than directly in the HTML. This means replacing the <script> tag while retaining the <form> tag:

<form id="foss-5c4aee3dlm28b054712ae0f1"></form>

>> the form id is an example, replace it with your own

The contents of the <script> tag will be called in javascript as below:

var field_value = "dynamic value" // Get dynamic value
var h=document.createElement('script');
h.setAttribute('src','URL_OF_PLEZI_PLEZI'+'&field_technique_name_plezi='+field_value);
document.head.appendChild(h);

By supplying the parameter(s) and their corresponding values, the Plezi form builder can itself fill in the values in the corresponding fields.

If it occurs to you to edit the value of one or more hidden fields in javascript, don't! You'd have to run the script responsible for this operation when the Plezi form is fully loaded. However, it is not currently possible to obtain this information.


2. If you want to change the value of a form field embedded in a Plezi landing page, you can do so by clicking here.

To do this, you need :

  1. Find the id of your hidden field. In the screenshot below, the id is jsonform-1-elt-partenaire.

2. Insert your script to retrieve and edit the hidden field in the JavaScript code field of the landing page.

Example of commonly used value recovery

Retrieve a URL parameter (utm_campaign in the example)

var getUrlParameter = function getUrlParameter(sParam) {
var sPageURL = decodeURIComponent(window.location.search.substring(1)),
sURLVariables = sPageURL.split('&'),
sParameterName,
i;

for (i = 0; i < sURLVariables.length; i++) {
sParameterName = sURLVariables[i].split('=');

if (sParameterName[0] === sParam) {
return sParameterName[1] === undefined ? true : sParameterName[1];
}
}
};
var valeur_du_champ = getUrlParameter('utm_campaign');

Example of modifying a hidden field in a Plezi landing page

// Modification de la valeur du champ caché

var setHiddenValueSelectField = function setHiddenValueSelectField(fieldId, value) {
document.getElementById(fieldId).value = value;
};

// Appel aux fonctions avec pour exemple :
// - a hidden field with id jsonform-1-elt-partenaire
// - a parameter called 'partner

var checkExist = setInterval(function() {
if (document.getElementById('jsonform-1-elt-partenaire') != null) {
clearInterval(checkExist);
setHiddenValueSelectField('jsonform-1-elt-partenaire', getUrlParameter('partner'));
}
}, 100);


Please note


If your must be equal to the value of the identification key (technical name).


The identification key can be found in the "Configuration > Contact qualification" page.

If your field is of the "Drop-down list" or "Multiple choice" type, then the value of your parameter will be found in "Configuration > Contact qualification - Value lists".

Did this answer your question?