empy first array value for cloneable group when using rwmb_frontend_validate
Support › MB Frontend Submission › empy first array value for cloneable group when using rwmb_frontend_validate
- This topic has 3 replies, 3 voices, and was last updated 2 months, 3 weeks ago by
Nicholas Cox.
-
AuthorPosts
-
January 19, 2025 at 10:23 PM #47466
Nicholas Cox
ParticipantHi, when using the filter
rwmb_frontend_validate
with a field which is cloneable group and noticed when i iterate over the array of values that the first array value is empty? why is this as the front end form only displays one set of fields for this group. I want to iterate over the keys and values but wondered why i have to skip the first value? is this deliberate?field
[ 'type' => 'group', 'id' => 'paypal', 'name' => 'PayPal Accounts', 'group_title' => 'PayPal', 'clone' => true, 'collapsible' => false, 'default_state' => 'expanded', 'save_state' => false, 'clone_empty_start' => true, 'add_button' => '+ Add PayPal', 'fields' => [ [ 'type' => 'text', 'name' => 'Email', 'id' => 'email', 'required' => false, 'columns' => 6, ], ], ]
output in 'rwmb_frontend_validate' using
error_log(print_r($_POST, true));
[19-Jan-2025 15:10:14 UTC] Array ( [mbfs_key] => 0b93a40cc6b6156f09107c3b29bd23e9 [action] => mbfs_submit [nonce_dcp-payment-gateways] => 56fce2e58a [_wp_http_referer] => /dcplatform/payment-gateways/ [user_id] => 1 [data] => Array ( [stripe] => Array ( [live_secret_key] => ssssssssssssssss ) [paypal] => Array ( [0] => Array ( [email] => ) [1] => Array ( [email] => [email protected] ) ) ) [rwmb_cleanup] => Array ( [0] => [\"data.paypal\"] ) [_ajax_nonce] => b7f61d3ba3 )
January 21, 2025 at 9:58 AM #47482Tan Nguyen
ParticipantDear Nicholas,
Since we introduced clone empty start feature, we need somewhere to store the template for cloneable fields, thats why we put the first empty element in an array for the template and have
rwmb_cleanup
to instruct the data parser to remove the template from actual data, in this case data.paypal[0].Every plugin that have this feature does the same somehow, ACF puts the template in the end of array.
Cheers!
January 21, 2025 at 12:46 PM #47483Peter
ModeratorIf you open the Console tab and check the HTML elements, you can see the first entry is the template that will be used for other clone entries. Screenshot https://imgur.com/CwZGTSs
January 21, 2025 at 9:23 PM #47488Nicholas Cox
ParticipantHi yes but when validating using
rwmb_frontend_validate
you have to do additional checks to see if the first value is empty or not also if the clone max is set to 1 then the array is no longer a nested array which means another check to see if its a single array or nested array.I was just checking with you as there is inconsistencies in the array returned when different settings are enabled and disabled, there is no guide on metabox validation array checks in the docs and what to look out for.
thanks
Nick
-
AuthorPosts
- You must be logged in to reply to this topic.