[Forminator Pro] Using API with forms

We successfully with your help set-up a form a few weeks ago with your help to send data via the API. To do this you told us how to add a "mu-plugins" folder and two php files, "frmt-send-mail-with-json.php" and "submit_json_to_api.php.

We now want to do something a bit better for a new form, send a request via a form to validate the email address stored in the clients DB.

We decided one way of doing this would be to set the form to redirect to a page on submitting the data. When the submit calls the ‘after save event’ we change the value of the ‘redirect-url’ from one link (default will be fail, try again) to a page for success etc, depending on the return value of the API call.

We wrote some test code to prove the theory, but the calls to change the form settings simply do not work. We tried several different methods all from the website documentation you provide and they appear successful, but if we re-read the form it remains unchanged.

We then tried to overwrite the form with a call to update_form(,,) and that does change the form. We can’t use this else we would have to write all forms in code! (We can’t pass the get_form() data to return the current form, then change one value and write it back as the data from get_form is not the same structure at the parameters update_form() needs.

I will need to send you the modified php test file we use to run the code (PHP) – the calls are in the method right near the bottom, lines 400+.

I have attached a snippet of the logs (…LOG) showing the before and after calls.

I have included all the code for this, including writing the logs.

Code snippet is:

write_pm_log('// 0':wink:;

$form_in_code = Forminator_API::get_form( $form_id );

write_pm_log($form_in_code);

// 1

$setting = 'redirect-url';

$value = 'https://example.com/';

$fields = Forminator_API::update_form_setting( $form_id, $setting, $value );

write_pm_log('// 1':wink:;

write_pm_log($fields);

// 2

$setting = 'form-padding-top';

$value = '30px';

$fields = Forminator_API::update_form_setting( $form_id, $setting, $value );

write_pm_log('// 2':wink:;

write_pm_log($fields);

// 3

$settings = array(

'form-padding-top' => '45px',

'cform-label-font-size' => '20'

);

$fields = Forminator_API::update_form_settings( $form_id, $settings );

write_pm_log('// 3':wink:;

write_pm_log($fields);

// 4

$form_in_code = Forminator_API::get_form( $form_id );

write_pm_log('// 4':wink:;

write_pm_log($form_in_code);

// Proof of concept:

// but if we use the example code to create wrappers / settings arrays from:

// https://gist.githubusercontent.com/bappi-d-great/184fea56d3e75497c267c197b2500b71/raw/943ef72fd07c5aedc71b190c84dc97cceb86facd/update_form.php

// then call:

// Forminator_API::update_form($form_id, $wrappers, $settings);

// the form gets overwritten completely

// $form_in_code = Forminator_API::get_form( $form_id );

// e.g.:

// update_test_form($form_id)

// write_pm_log($form_in_code);

Could you please advise where we might be going wrong

I have allowed support access to the site and the test site: urbanspace.dsm.pw that we currently are testing on