Entering a token in a field

By: Karol dionizy | Asked: 09/27/2023
ForumsCategory: Code HelpEntering a token in a field
Karol dionizy asked 7 months ago

I would like some help there is a hidden field on the form, it should include a generated identifier that can be used to refer to it later here is the code I put in functions.php


  function set_formidable_token($values) {
error_log("Function is triggered"); 
error_log("Form ID from values: " . $values['view_id']);
error_log(print_r($values, true));

if ($values['form_id'] == 2) {
error_log("Form ID condition is met"); 
$token = generateStrongToken();
$values['item_meta'][135] = $token; 
error_log("Token after generation: " . $token);
return $values;  

I would refer to the ID of the form, which is: 2
and the code of the hidden field on the form is 135 however, it does not enter the cycle unless I enter the ID of "views".

How can I solve this?
The token code is generated, I check this with the error_log  

thx Karol

Rob LeVineRob LeVine replied 7 months ago

From what formidable hook are you calling this method, i.e., what function is passing "$values" in?

Karol dionizy replied 7 months ago

the routine runs automatically before storing the form

Rob LeVineRob LeVine replied 7 months ago

That doesn't make sense to me. That function is a custom function, not a formidable one, so either you're explicitly calling it or it's the callback function in one of the hooks.

1 Answers
Victor Font answered 7 months ago
You should be using your function as the callback function for the frm_pre_create_entry filter. https://formidableforms.com/knowledgebase/frm_pre_create_entry/

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community