Support Forum
Hi,
I have a problem with one of my user profile forms. The form has been working fine until I added some extra fields to it. Now the extra field values are not being saved consistently.
The form has a little over 100 fields in total and they are structured as al being inside a group with some of them arranged as subgroups.
I call the form in 2 different ways (from different front end pages).
In one call the user is logged in themselves and the form is called using a shortcode on a page using:
[mb_user_profile_info id="cip_pet_details" submit_button="Update Your Details" confirmation="Your Pet Details section has been successfully submitted. Thank you."]
In the second location the logged in user is an admin so the shortcode (called from a View) is this:
[mb_user_profile_info id='cip_pet_details' user_id={{ GET.user_id }} label_submit="Save Pet Details" confirmation=""]
In this second call the user_id is passed as a value in the URL.
In both cases the form has been working fine. The only difference in behaviour is that in the second location the newly added field values are being correctly saved but in the first the values are being sent to save but are not actually being stored in the database.
On both of the pages in question I have a further 10 forms which are all behaving correctly in both locations and there are no differences to the above shortcode structures for them.
The newly added fields are at various locations throughout the form and although the new fields were added in a newer version of MB to the original form there seems to be no difference in the structure of the code so I don't believe this is a problem with the form itself.
My guesses were related to data size being stored (but the db shouldn't have a limit there for data volume), the fact that there are over 100 fields (that has been confirmed on a separate topic as not being an issue with MB and the issues occurring as it went over 100 must be coincidental).
Any ideas to point me at what might be happening would be much appreciated.
Hi,
I think this issue is related to the PHP setting max_input_vars
, you can try to follow this tutorial to fix the issue https://metabox.io/wordpress-custom-fields-not-saving-increase-max-input-vars/
I've tried increasing but I already had it set pretty high. I was on 100000 before and bumped it up to 1000000 with no change in behaviour.
I've been trying some different scenarios and I've found that the behaviour isn't quite as described.
It seems that when the form is opened up and edited by admin using shortcode [mb_user_profile_info id='cip_pet_details' user_id={{ GET.user_id }} label_submit="Save Pet Details" confirmation=""] with the user id being passed in the URL the form values will update fine.
When I use the same shortcode (but without the user_id argument so it uses the currently logged in user) when logged in as a user it shows the saved values fine but none of the fields will update when changes are submitted.
I have tested that all other circumstances are the same by using a duplicate of the admin page. To my thinking this means that the only difference now between the two is the logged in user role.
I've made further tests and this is the result. All value updates made by the admin user through the form are working fine.
All value changes made by a standard user are failing. I've even reduced the form to it's minimum level as below with only one remaining field which still fails to save.
I wonder if there are settings against the user role which I need to check to ensure the values are saved to the database? I use Members from MemberPress for the sole reason of creating my custom users roles if there may be an issue there?
add_filter( 'rwmb_meta_boxes', 'test_cip_pet' );
function test_cip_pet( $meta_boxes ) {
$prefix = '';
$meta_boxes[] = [
'title' => __( 'TEST - Pet Details', 'your-text-domain' ),
'id' => 'test_pet_details',
'type' => 'user',
'include' => [
'relation' => 'AND',
'user_role' => ['um_client', 'administrator'],
'edited_user_role' => ['um_client'],
],
'fields' => [
[
'id' => $prefix . 'group_pet_details',
'type' => 'group',
'fields' => [
[
'name' => __( 'Specify details for each of your pets.', 'your-text-domain' ),
'id' => $prefix . 'group_pet',
'type' => 'group',
'collapsible' => true,
'group_title' => '{pet_name} - {pet_breed}',
'clone' => true,
'max_clone' => 20,
'add_button' => __( 'Add another pet...', 'your-text-domain' ),
'fields' => [
[
'name' => __( 'Pet\'s Name', 'your-text-domain' ),
'id' => $prefix . 'pet_name',
'type' => 'text',
'required' => true,
],
],
],
],
],
],
];
return $meta_boxes;
}
OK. Resolved it. Please ignore all the above. It turned out that another plugin had registered a role that was clashing with my client role (2 roles with the same name). It seems the admin user could see and edit the details regardless of the edited user roles but the user could only see the values and not update them. The clashing role is now gone and everything is working again.
Hi,
Thanks for sharing the solution.
For the next time, you can deactivate all plugins except Meta Box, and MB extensions, and switch to the standard theme of WordPress (Twenty TwentyTwo) to debug the issue easier.