NB: Make sure you do a back up of your theme, files and database before attempting the tutorials
Last modified : Nov 17 2021
Estimated reading time : 1 minute, 39 seconds - 255 words
Share the post "Creating a Custom Entry ID For Formidable Form"
This tutorial will show you how to create a custom ID or number for a Formidable Form and then update it with a custom field.
The purpose of this function will be to generate an ID number for your ticket such as PO number, business number, reference number, etc…
First of all, we will need to create a shortcode and include within it a PHP generator: the mt_rand(). This generates a random value via the Mersenne Twister.
Donc nous allons dans notre functions.php de notre WordPress et nous allons construire notre shortcode qui sera [idrand]. Dans cette fonction shortcode on lui demande de générer un nombre. On peut vérifier sur le site, mais vous pouvez personnaliser ou argumenter votre mt_rand().
Ex: Generate a number between 5 and 2000, you’d do this: mt_rand(5, 2000);.
In this case, we could simply ask the generator to generate a number without arguments so it could generate 87459612 for example.
// Add Shortcode function mafunction_number_entreprise_shortcode() { return mt_rand() . "\n"; } add_shortcode( 'idrand', 'mafunction_number_entreprise_shortcode' );
Once you’ve inserted the shortcode, we will add a hidden field in the form where you will add the shortcode as its default value.
Afterwards, we need to test the shortcode with the form to make sure it generates a number and that it’s not visible to users when they fill out the form.
Vous pouvez bien sur avec votre formulaire Formidable form, générer une action qui va permettre d’ajouter toutes les valeurs de votre formulaire dans un post type et ses champs personnalisés.
(Tutoriel prochain)