user-edit.php – settings registered – _POST[val] not in HTTP Request
-
Greetings.
I’m working on a custom plugin which puts custom fields in the User Profile. I have 2 diff types of fields. One is for mobile_number. That part works. I have another group of checkbox items. They’re both meant to useupdate_user_meta()
when the form processes, but my checkboxes aren’t updating.
While debugging (xdebug stepping w/ VS Code), I see that the _POST[checkboxes] values are there at first, but then (after some native functions process) the http _POST request values are no longer there, and _GET is populated with the &user_id and &wp_http_referer . I’ve not seen this sort of thing before. (Is that a result of Ajax?)
My database queries etc work correctly outside of having the code in the User Profile page.
Here’s a chunk of what i’m working with. What do you recommend I look for?
The function to process the _REQUEST data /update_user_meta()
:public function zto_membergroup_members() { $zto_helpers = new Zto_Helpers(); if (isset($_REQUEST['updated'])) { $membergroups_from_db = get_user_meta($user_id, 'zto_membergroup'); $membergroups = \wp_parse_args($membergroups_from_db, $zto_helpers->zto_membergroup_defaults()); $membergroups['zto_membergroup_one'] = sanitize_text_field($_REQUEST['zto_membergroup']['zto_membergroup_one']); $membergroups['zto_membergroup_two'] = sanitize_text_field($_REQUEST['zto_membergroup']['zto_membergroup_two']); $membergroups['zto_membergroup_three'] = sanitize_text_field($_REQUEST['zto_membergroup']['zto_membergroup_three']); $membergroups['zto_membergroup_four'] = sanitize_text_field($_REQUEST['zto_membergroup']['zto_membergroup_four']); $membergroups['zto_membergroup_five'] = sanitize_text_field($_REQUEST['zto_membergroup']['zto_membergroup_five']); } else { $membergroups = $zto_helpers->zto_membergroup_defaults(); } update_user_meta($user_id, 'zto_membergroup', $membergroups); }
The HTML for the form for the User Profile fields:
<th><label for="mobile_number">Mobile Number:</label></th> <td><input type="text" name="mobile_number" id="mobile_number" placeholder="9876543210" value="<?php echo $mobile_number ? $mobile_number : ''; ?>" class="regular-text"></td> </tr> <?php $user_membership = get_user_meta($user_id, 'zto_membergroup'); $user_membership = wp_parse_args($user_membership, $zto_helpers_general->zto_membergroup_defaults()); $html_concat .= '<tr><td><label for="'; $html_concat .= esc_html('zto_membergroup').'[zto_membergroup_one]" id="zto_membergroup_one">Group One Member</label>'; $html_concat .= '<input class="cm-toggle" type="checkbox" name="'; $html_concat .= esc_html('zto_membergroup').'[zto_membergroup_one]" id="'; $html_concat .= esc_html('zto_membergroup').'[zto_membergroup_one]" value="1" '; $html_concat .= checked($user_membership['zto_membergroup_one'], '1', true).'> </td></tr> ';
Thank you!
- The topic ‘user-edit.php – settings registered – _POST[val] not in HTTP Request’ is closed to new replies.