dynamic model form population error
Support › MB Frontend Submission › dynamic model form population error
- This topic has 8 replies, 2 voices, and was last updated 1 month, 2 weeks ago by
Peter.
-
AuthorPosts
-
February 5, 2025 at 10:05 PM #47598
Nicholas Cox
ParticipantHi
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.
February 6, 2025 at 11:53 PM #47612Peter
ModeratorHello 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.
February 26, 2025 at 12:26 AM #47740Nicholas Cox
ParticipantHi 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.
thanks
Nick
February 26, 2025 at 9:05 PM #47746Peter
ModeratorHello 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.February 26, 2025 at 10:19 PM #47748Nicholas Cox
Participantyes 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; }
February 26, 2025 at 11:07 PM #47750Nicholas Cox
ParticipantHi, 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?
February 26, 2025 at 11:10 PM #47751Nicholas Cox
Participantwhen setting the max_clone to 2 or more this is not an issue with auto populating forms, just when its set to 1.
February 26, 2025 at 11:17 PM #47752Nicholas Cox
Participantalso 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.February 27, 2025 at 10:33 PM #47754Peter
ModeratorHello 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 -
AuthorPosts
- You must be logged in to reply to this topic.