Saving Select Advanced user selection as user_meta

Support MB User Meta Saving Select Advanced user selection as user_meta

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #17437
    Carey RobinsonCarey Robinson
    Participant

    I've created a form for updating custom user_meta. The form uses conditional logic to show specific text input fields based on the options chosen from a collection of "Select Advanced" Fields.

    When the form is submitted the data from the text input fields is posted to the user meta data, but the user selections from the select fields are not saved in the user meta data. I need to record the users' choices for each select field used as meta_values assigned to an established meta_key in the user meta data in addition to the input field data.

    How do I accomplish this?

    Here's the code for a truncated version of my form:

    
    function sw_user_license_profile( $meta_boxes ) {
        $prefix = 'sw-';
    
        $meta_boxes[] = array(
            'type'=> 'user',
            'id' => $prefix . 'profile-license',
            'title' => esc_html__( 'Add/Update License Information', 'company' ),
            'context' => 'normal',
            'priority' => 'default',
            'autosave' => 'true',
            'fields' => array(
                array(
                    'id' => $prefix . 'license-authority',
                    'name' => esc_html__( 'State of License', 'company' ),
                    'type' => 'select_advanced',
                    'std' => array(
                        0 => '',
                    ),
                    'placeholder' => esc_html__( 'Select an State', 'company' ),
                    'options' => array(
                        array( 'value' => 'not_licensed', 'label' => 'Not Licensed' ),
                        array( 'value' => 'ca', 'label' => 'California' ),
                        array( 'value' => 'ma', 'label' => 'Massachusetts' ),
                    ),
                    'class' => 'sw-license-label',
                    'multiple' => 1,
                    'required' => 1,
                ),
                array(
                    'id' => $prefix .'heading_ca',
                    'type' => 'heading',
                    'class' => 'h4',
                    'name' => esc_html__( 'California Operator Licenses', 'company' ),
                    'visible' => array(
                        'when' => array(
                            array (
                                0 => $prefix . 'license-authority',
                                1 => 'contains',
                                2 => 'ca',
                            ),
                        ),
                        'relation' => 'and',
                    ),
                ),
                array(
                    'id' => $prefix . 'license-authority-ca',
                    'name' => esc_html__( 'License Type', 'company' ),
                    'type' => 'select_advanced',
                    'std' => array(
                        0 => '',
                    ),
                    'placeholder' => esc_html__( 'Select a License', 'company' ),
                    'options' => array(
                        array( 'value' => 'dwd_lic_ca', 'label' => 'Drinking Water Distribution Operator' ),
                        array( 'value' => 'dwt_lic_ca', 'label' => 'Drinking Water Treatment Operator' ),
                        array( 'value' => 'ww_lic_ca', 'label' => 'Wastewater Operator' ),
                        array( 'value' => 'other_lic_ca', 'label' => 'Other California License Type'),
                    ),
                    'class' => 'sw-license-label',
                    'flatten' => false,
                    'visible' => array(
                        'when' => array(
                            array (
                                0 => $prefix . 'license-authority',
                                1 => 'contains',
                                2 => 'ca',
                            ),
                        ),
                        'relation' => 'and',
                    ),
                    'class' => 'sw-license-label',
                    'multiple' => 1,
                    'required' => 1,
                ),
                array(
                    'id' => 'dwd_lic_ca',
                    'type' => 'text',
                    'name' => esc_html__( 'Drinking Water Distribution License #', 'company' ),
                    'required' => 1,
                    'visible' => array(
                        'when' => array(
                            array (
                                0 => $prefix . 'license-authority-ca',
                                1 => 'contains',
                                2 => 'dwd_lic_ca',
                            ),
                        ),
                        'relation' => 'and',
                    ),
                    'class' => 'sw-license-input',
                ),
                array(
                    'id' => 'dwt_lic_ca',
                    'type' => 'text',
                    'name' => esc_html__( 'Drinking Water Treatment License #', 'company' ),
                    'required' => 1,
                    'visible' => array(
                        'when' => array(
                            array (
                                0 => $prefix . 'license-authority-ca',
                                1 => 'contains',
                                2 => 'dwt_lic_ca',
                            ),
                        ),
                        'relation' => 'and',
                    ),
                    'class' => 'sw-license-input',
                ),
                array(
                    'id' => 'ww_lic_ca',
                    'type' => 'text',
                    'name' => esc_html__( 'Wastewater License #', 'company' ),
                    'required' => 1,
                    'visible' => array(
                        'when' => array(
                            array (
                                0 => $prefix . 'license-authority-ca',
                                1 => 'contains',
                                2 => 'ww_lic_ca',
                            ),
                        ),
                        'relation' => 'and',
                    ),
                    'class' => 'sw-license-input',
                ),
                array(
                    'id' => $prefix .'heading_ca_other',
                    'type' => 'heading',
                    'class' => 'h5',
                    'name' => esc_html__( 'Other California License', 'company' ),
                    'visible' => array(
                        'when' => array(
                            array (
                                0 => $prefix . 'license-authority-ca',
                                1 => 'contains',
                                2 => 'other_lic_ca',
                            ),
                        ),
                        'relation' => 'and',
                    ),
                ),
                array(
                    'id' => 'other_type_ca',
                    'type' => 'text',
                    'name' => esc_html__( 'License Type', 'company' ),
                    'required' => 1,
                    'visible' => array(
                        'when' => array(
                            array (
                                0 => $prefix . 'license-authority-ca',
                                1 => 'contains',
                                2 => 'other_lic_ca',
                            ),
                        ),
                        'relation' => 'and',
                    ),
                    'class' => 'sw-license-input',
                ),
                array(
                    'id' => 'other_lic_ca',
                    'type' => 'text',
                    'name' => esc_html__( 'License #', 'company' ),
                    'required' => 1,
                    'visible' => array(
                        'when' => array(
                            array (
                                0 => $prefix . 'license-authority-ca',
                                1 => 'contains',
                                2 => 'other_lic_ca',
                            ),
                        ),
                        'relation' => 'and',
                    ),
                    'class' => 'sw-license-input',
                ),
                array(
                    'id' => $prefix .'heading_ma',
                    'type' => 'heading',
                    'class' => 'h4',
                    'name' => esc_html__( 'Massachusetts Operator Licenses', 'company' ),
                    'visible' => array(
                        'when' => array(
                            array (
                                0 => $prefix . 'license-authority',
                                1 => 'contains',
                                2 => 'ma',
                            ),
                        ),
                        'relation' => 'and',
                    ),
                ),
                array(
                    'id' => $prefix . 'license-authority-ma',
                    'name' => esc_html__( 'License Type', 'company' ),
                    'type' => 'select_advanced',
                    'std' => array(
                        0 => '',
                    ),
                    'placeholder' => esc_html__( 'Select a License', 'company' ),
                    'options' => array(
                        array( 'value' => 'dwc_lic_ma', 'label' => 'Drinking Water Dual Certification (C1-C4)' ),
                        array( 'value' => 'dwd_lic_ma', 'label' => 'Drinking Water Distribution (D1-D4|DA-DD)' ),
                        array( 'value' => 'dwt_lic_ma', 'label' => 'Drinking Water Treatment (T1-T4|TA-TD)' ),
                        array( 'value' => 'vnd_lic_ma', 'label' => 'Drinking Water Vending Machine (N1-N4|NA|NB)' ),
                        array( 'value' => 'vss_lic_ma', 'label' => 'Very Small System (VS|VT)' ),
                        array( 'value' => 'wwi_lic_ma', 'label' => 'Industrial Wastewater (1I-4I)' ),
                        array( 'value' => 'wwm_lic_ma', 'label' => 'Municipal Wastewater (1M-4M)' ),
                        array( 'value' => 'wwc_lic_ma', 'label' => 'Combined Wastewater (5C-6C)' ),
                        array( 'value' => 'other_lic_ma', 'label' => 'Other Massachusetts License Type'),
                    ),
                    'class' => 'sw-license-label',
                    'flatten' => false,
                    'visible' => array(
                        'when' => array(
                            array (
                                0 => $prefix . 'license-authority',
                                1 => 'contains',
                                2 => 'ma',
                            ),
                        ),
                        'relation' => 'and',
                    ),
                    'class' => 'sw-license-label',
                    'multiple' => 1,
                    'required' => 1,
                ),
                array(
                    'id' => 'dwc_lic_ma',
                    'type' => 'text',
                    'name' => esc_html__(  'Drinking Water Dual Certification #', 'company' ),
                    'desc' => esc_html__( '(C1-C4)', 'company' ),
                    'required' => 1,
                    'visible' => array(
                        'when' => array(
                            array (
                                0 => $prefix . 'license-authority-ma',
                                1 => 'contains',
                                2 => 'dwc_lic_ma',
                            ),
                        ),
                        'relation' => 'and',
                    ),
                    'class' => 'sw-license-input',
                ),
                array(
                    'id' => 'dwd_lic_ma',
                    'type' => 'text',
                    'name' => esc_html__(  'Drinking Water Distribution License #', 'company' ),
                    'desc' => esc_html__( '(D1-D4|DA-DD)', 'company' ),
                    'required' => 1,
                    'visible' => array(
                        'when' => array(
                            array (
                                0 => $prefix . 'license-authority-ma',
                                1 => 'contains',
                                2 => 'dwd_lic_ma',
                            ),
                        ),
                        'relation' => 'and',
                    ),
                    'class' => 'sw-license-input',
                ),
                array(
                    'id' => 'dwt_lic_ma',
                    'type' => 'text',
                    'name' => esc_html__(  'Drinking Water Treatment License #', 'company' ),
                    'desc' => esc_html__( '(T1-T4|TA-TD)', 'company' ),
                    'required' => 1,
                    'visible' => array(
                        'when' => array(
                            array (
                                0 => $prefix . 'license-authority-ma',
                                1 => 'contains',
                                2 => 'dwt_lic_ma',
                            ),
                        ),
                        'relation' => 'and',
                    ),
                    'class' => 'sw-license-input',
                ),
                array(
                    'id' => 'vnd_lic_ma',
                    'type' => 'text',
                    'name' => esc_html__(  'Drinking Water Vending Machine License #', 'company' ),
                    'desc' => esc_html__( '(N1-N4|NA|NB)', 'company' ),
                    'required' => 1,
                    'visible' => array(
                        'when' => array(
                            array (
                                0 => $prefix . 'license-authority-ma',
                                1 => 'contains',
                                2 => 'vnd_lic_ma',
                            ),
                        ),
                        'relation' => 'and',
                    ),
                    'class' => 'sw-license-input',
                ),
                array(
                    'id' => 'vss_lic_ma',
                    'type' => 'text',
                    'name' => esc_html__(  'Very Small System License #', 'company' ),
                    'desc' => esc_html__( '(VS|VT)', 'company' ),
                    'required' => 1,
                    'visible' => array(
                        'when' => array(
                            array (
                                0 => $prefix . 'license-authority-ma',
                                1 => 'contains',
                                2 => 'vss_lic_ma',
                            ),
                        ),
                        'relation' => 'and',
                    ),
                    'class' => 'sw-license-input',
                ),
                array(
                    'id' => 'wwi_lic_ma',
                    'type' => 'text',
                    'name' => esc_html__(  'Industrial Wastewater License #', 'company' ),
                    'desc' => esc_html__( '(1I-4I)', 'company' ),
                    'required' => 1,
                    'visible' => array(
                        'when' => array(
                            array (
                                0 => $prefix . 'license-authority-ma',
                                1 => 'contains',
                                2 => 'wwi_lic_ma',
                            ),
                        ),
                        'relation' => 'and',
                    ),
                    'class' => 'sw-license-input',
                ),
                array(
                    'id' => 'wwm_lic_ma',
                    'type' => 'text',
                    'name' => esc_html__(  'Municipal Wastewater License #', 'company' ),
                    'desc' => esc_html__( '(1M-4M)', 'company' ),
                    'required' => 1,
                    'visible' => array(
                        'when' => array(
                            array (
                                0 => $prefix . 'license-authority-ma',
                                1 => 'contains',
                                2 => 'wwm_lic_ma',
                            ),
                        ),
                        'relation' => 'and',
                    ),
                    'class' => 'sw-license-input',
                ),
                array(
                    'id' => 'wwc_lic_ma',
                    'type' => 'text',
                    'name' => esc_html__(  'Combined Wastewater License #', 'company' ),
                    'desc' => esc_html__( '(5C-6C)', 'company' ),
                    'required' => 1,
                    'visible' => array(
                        'when' => array(
                            array (
                                0 => $prefix . 'license-authority-ma',
                                1 => 'contains',
                                2 => 'wwc_lic_ma',
                            ),
                        ),
                        'relation' => 'and',
                    ),
                    'class' => 'sw-license-input',
                ),
                array(
                    'id' => $prefix .'heading_ma_other',
                    'type' => 'heading',
                    'class' => 'h5',
                    'name' => esc_html__( 'Other Massachusetts License', 'company' ),
                    'visible' => array(
                        'when' => array(
                            array (
                                0 => $prefix . 'license-authority-ma',
                                1 => 'contains',
                                2 => 'other_lic_ma',
                            ),
                        ),
                        'relation' => 'and',
                    ),
                ),
                array(
                    'id' => 'other_type_ma',
                    'type' => 'text',
                    'name' => esc_html__(  'License Type', 'company' ),
                    'required' => 1,
                    'visible' => array(
                        'when' => array(
                            array (
                                0 => $prefix . 'license-authority-ma',
                                1 => 'contains',
                                2 => 'other_lic_ma',
                            ),
                        ),
                        'relation' => 'and',
                    ),
                    'class' => 'sw-license-input',
                ),
                array(
                    'id' => 'other_lic_ma',
                    'type' => 'text',
                    'name' => esc_html__(  'License #', 'company' ),
                    'required' => 1,
                    'visible' => array(
                        'when' => array(
                            array (
                                0 => $prefix . 'license-authority-ma',
                                1 => 'contains',
                                2 => 'other_lic_ma',
                            ),
                        ),
                        'relation' => 'and',
                    ),
                    'class' => 'sw-license-input',
                ),
            ),
        );
        return $meta_boxes;
    }
    add_filter( 'rwmb_meta_boxes', 'sw_user_license_profile' );
Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.