Hello everybody,
I’m trying to programmaticaly submit some forms, where each form contains a field called “User Id” with the ID 999.
Here’s what my code looks like :
$input_values['input_999'] = $user_id; // for exemple 19
foreach ($forms as $form){
$result = GFAPI::submit_form( $form, $input_values );
}
Where $forms
would for example be :
$forms = [57,58,59,60,61];
But when this code runs,
all the forms are indeed submitted.
But only the first form of the array $forms[0]
receives the $input_values and the proper user id.
All the other ones are instead filled with “0” instead of the given id.
This happens every time I used multiple GFAPI::submit_form.
Does any one know what I’m doing wrong ?
richardw8k
(Richard Wawrzyniak (Gravity Forms))
November 10, 2021, 11:59am
2
GFAPI::submit_form()
isn’t designed to be used in a loop; you’ll need to perform some cleanup at the end of each loop e.g.
{
$result = GFAPI::submit_form( $form_id, $input_values );
$_POST = array();
GFFormsModel::flush_current_lead();
GFFormDisplay::$submission = array();
}
4 Likes
This worked perfectly !
Thank you, I was expecting such a behavior but couldn’t figure it out myself. Huge thanks
JamieO
(Jamie (Gravity Flow))
November 14, 2021, 11:19pm
5
Glad you have been able to resolve your issue @jonathanpak !
For others that might be reading this ticket after and looking for a solution that doesn’t involve code to do a similar task, the Gravity Flow Form Connector extension provides a no-code approach . With its’ create an entry step you also have flexibility to control what field(s) are mapped from the originating entry into the other form entries.
2 Likes