Support Forum
Support › MB Frontend Submission › Multiple frontend & nested valuesResolved
Hi there!
I need to create multiple frontend forms that share the same custom fields. I have run a couple of tests with identical setup:
Test 1:
<?php
add_filter( 'rwmb_meta_boxes', 'your_prefix_function_name' );
function your_prefix_function_name( $meta_boxes ) {
$prefix = '';
$meta_boxes[] = [
'title' => __( 'Test 1', 'your-text-domain' ),
'id' => 'test_form_1',
'post_types' => ['research'],
'fields' => [
[
'name' => __( 'Title', 'your-text-domain' ),
'id' => $prefix . 'post_title',
'type' => 'text',
],
[
'name' => __( 'A cloneable value', 'your-text-domain' ),
'id' => $prefix . 'a_cloneable_value',
'type' => 'group',
'fields' => [
[
'name' => __( 'Option 1', 'your-text-domain' ),
'id' => $prefix . 'option_1',
'type' => 'text',
],
[
'name' => __( 'Nested', 'your-text-domain' ),
'id' => $prefix . 'nested ',
'type' => 'group',
'clone' => true,
'fields' => [
[
'name' => __( 'Option 2', 'your-text-domain' ),
'id' => $prefix . 'option_2',
'type' => 'text',
],
],
],
],
],
],
];
return $meta_boxes;
}
Test 2:
<?php
add_filter( 'rwmb_meta_boxes', 'your_prefix_function_name' );
function your_prefix_function_name( $meta_boxes ) {
$prefix = '';
$meta_boxes[] = [
'title' => __( 'Test 2', 'your-text-domain' ),
'id' => 'test_form_2',
'post_types' => ['research'],
'fields' => [
[
'name' => __( 'Title', 'your-text-domain' ),
'id' => $prefix . 'post_title',
'type' => 'text',
],
[
'name' => __( 'A cloneable value', 'your-text-domain' ),
'id' => $prefix . 'a_cloneable_value',
'type' => 'group',
'fields' => [
[
'name' => __( 'Text', 'your-text-domain' ),
'id' => $prefix . 'option_1',
'type' => 'text',
],
[
'name' => __( 'Group', 'your-text-domain' ),
'id' => $prefix . 'nested',
'type' => 'group',
'clone' => true,
'fields' => [
[
'name' => __( 'Text', 'your-text-domain' ),
'id' => $prefix . 'option_2',
'type' => 'text',
],
],
],
],
],
],
];
return $meta_boxes;
}
But my issue is that the nested field values are not saved across the form. So the option_2
saves in one form but does not save / update in the other. I tried changing the IDs incase of a conflict. Is this a bug or something I am doing wrong? Wanting to understand before going ahead and building a lot of form duplicates!
Many thanks,
Yasmine
And just incase it matters - option_1
value shows
You can close this - there was a space after the id nested
.
I changed the option_2 ID but not the group - until now..
Think it would be useful if IDs were trimmed of white space upon save though!