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

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #47466
    Nicholas CoxNicholas Cox
    Participant

    Hi, 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
    )
    #47482
    Tan NguyenTan Nguyen
    Participant

    Dear 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!

    #47483
    PeterPeter
    Moderator

    If 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

    #47488
    Nicholas CoxNicholas Cox
    Participant

    Hi 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

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.