dynamic model form population error

Support MB Frontend Submission dynamic model form population error

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

    Hi

    Im using the following shortcode [mb_frontend_form id="dcp-payment-gateways" edit="true" ajax="true" object_type="model"], is it possible to edit a model object id using the url query string e.g. ?rwmb_frontend_field_object_id=1

    When i test this i receive the following error message and it does not work.
    Warning: Attempt to read property "capability" on null in C:\wamp\www\dcplatform\wp-content\plugins\drip-create-platform\assets\vendor\meta-box\mb-frontend-submission\src\Form.php on line 151

    This works for posts, just not models.

    #47612
    PeterPeter
    Moderator

    Hello Nick,

    Yes, it is possible to edit a model with the URL query string:

    https://yoursite.com/model-frontend-page/?rwmb_frontend_field_object_id=123

    do you login with a user who can edit posts/models? Please share a screen record of the issue on your site.

    #47740
    Nicholas CoxNicholas Cox
    Participant

    Hi Peter,

    Sorry for the delay, was away. I have done a screen recording showing im signed in as an administrator who posted the entry and with one result in the model database table, the shortcode and the test page.

    Video Link

    thanks

    Nick

    #47746
    PeterPeter
    Moderator

    Hello Nick,

    Can you please create/submit a new model entry and recheck the issue? If it still doesn't work, please upload your local site to an online hosting and share the admin site account by submitting this contact form https://metabox.io/contact/
    I will take a look.

    #47748
    Nicholas CoxNicholas Cox
    Participant

    yes i add more entries and then try to edit them and i receive the same warning about capability.

    Ok ill setup a test site, but before here is the code im using incase im missing something.

    public function paymentGatewayFormFields( $meta_boxes ) {
    	
    	global $wpdb;
    
    	$meta_boxes[] = [
    		'title' => 'Payment Gateways',
    		'models' => [self::$paymentGatewayClientsModel],
    		'storage_type' => 'custom_table', 
    		'table'        => $wpdb->prefix . self::$paymentGatewayClientsTable,
    		'id'      => self::$metaboxFormId, 
    		'fields'  => [
    			[
    				'id'   => 'user_id',
    				'type' => 'hidden',
    				'std'  => get_current_user_id() ?? 0,
    			],
    			[
    				'type' => 'group',
    				'id'   => 'data',
    				'name' => 'Payment Gateways',
    				'group_title' => 'Payment Gateways',
    				'clone' => false,
    				'collapsible' => false,
    				'default_state' => 'collapsed',
    				'save_state' => false,
    				'save_field' => true,
    				'fields' => [
    					[
    						'type' => 'group',
    						'id'   => 'stripe',
    						'name' => 'Stripe Accounts',
    						'group_title' => 'Stripe',
    						'clone' => true,
    						'max_clone' => 1,		
    						'min_clone' => 0,				
    						'collapsible' => false,
    						'default_state' => 'expanded',
    						'save_state' => false,
    						'clone_empty_start' => true,
    						'add_button' => '+ Add Stripe',
    						'fields' => [
    							[
    								'id'   => 'id', //mysql table col
    								'type' => 'hidden',
    								'std'  => DripCreatePlatformHelper::generateRandomKeyByLength( 7 ),
    							],
    							[
    								'type'  => 'text',
    								'name'  => 'Domain', 
    								'id'    => 'domain', 
    								'required' => false,
    								'columns' => 4, 
    							],
    							[
    								'type'  => 'text',
    								'name'  => 'live Secret Key', 
    								'id'    => 'live_secret_key', 
    								'required' => false,
    								'columns' => 3, 
    							],
    							[
    								'type'  => 'text',
    								'name'  => 'Webhook Secret',
    								'id'    => 'live_webhook_secret',
    								//'limit' => 10,
    								'required' => false,
    								'columns' => 3,
    							],
    							[
    								'type'      => 'switch',
    								'name'      => 'Enabled',
    								'id'        => 'enabled',
    								'style'     => 'rounded',
    								'on_label'  => 'Yes',
    								'off_label' => 'No',
    								'std' 		=> 1,
    								'columns' => 2,
    							],
    						],
    					],
    				],	
    			],	
    		],
    	];
    	
    	return $meta_boxes;
    }
    #47750
    Nicholas CoxNicholas Cox
    Participant

    Hi, i have checked this over and recreated a new one and the problem has gone away but the issue still persisted with the population of the form using the url param ?rwmb_frontend_field_object_id=1

    I started to remove the settings in the form back and noticed the following setting for max_clone is causing the issue to populate groups from serialized arrays.

    'max_clone' => 1

    if i remove this then i can auto populate the form correctly and also successfully update the entry using the shortcode.

    So i assumed the form was not auto populating as my form only contains a group field. All other fields populate correctly.

    Any ideas why the max_clone of 1 is not working?

    #47751
    Nicholas CoxNicholas Cox
    Participant

    when setting the max_clone to 2 or more this is not an issue with auto populating forms, just when its set to 1.

    #47752
    Nicholas CoxNicholas Cox
    Participant

    also when editing using object_id=1 in the shortcode, can i set this so the user who made the entry can only edit the post? or is this setup to do it on a capability level only? as not sure from the docs that if this behaves like posts do.

    #47754
    PeterPeter
    Moderator

    Hello Nick,

    It could be related to the issue with cloneable group field and it has been fixed in the new version of Meta Box and Meta Box AIO. Can you please update those plugins and recheck the issue?

    Also, if you set the attribute object_id=1 to the frontend shortcode, the frontend submission form only allows editing the object ID 1. You can read more about shortcode attributes in the documentation
    https://docs.metabox.io/extensions/mb-frontend-submission/#adding-the-submission-form

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