Skip to content

Instantly share code, notes, and snippets.

@wpmudev-sls
Last active September 18, 2024 06:05
Show Gist options
  • Save wpmudev-sls/05a10641277a10e351713df508c0dccd to your computer and use it in GitHub Desktop.
Save wpmudev-sls/05a10641277a10e351713df508c0dccd to your computer and use it in GitHub Desktop.
[Forminator Pro]- Fix missing/hidden fields in form export causing form submission error, hidden fields in submission
<?php
/**
* Plugin Name: [Forminator Pro] Fix hidden or missing fields in form export causing multiple errors.
* Description: Fix hidden or missing fields in form export causing multiple errors.
* Author: Prashant @ WPMUDEV
* Task: SLS-6475
* Author URI: https://premium.wpmudev.org
* License: GPLv2 or later
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
add_action(
'wp_ajax_forminator_save_builder',
function () {
if ( ! isset( $_POST['data'] ) ) {
return;
}
$data = json_decode( wp_unslash( $_POST['data'] ), true );
if ( ! isset( $data['wrappers'] ) || empty( $data['wrappers'] ) ) {
return;
}
if ( 46603 !== intval( $data['settings']['form_id'] ) ) { // Please change 46603 to your form ID.
return;
}
$changed = false;
foreach ( $data['wrappers'] as $wrapper_key => $wrapper ) {
foreach ( $wrapper['fields'] as $k => $field ) {
if ( $field['parent_group'] !== $wrapper['parent_group'] ) {
$data['wrappers'][ $wrapper_key ]['fields'][ $k ]['parent_group'] = $wrapper['parent_group'];
$changed = true;
}
}
}
if ( $changed ) {
$_POST['data'] = addslashes( json_encode( $data ) );
}
},
8
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment