MjHead / jet-engine-extend-form-action

jet-engine-extend-form-action
5 stars 0 forks source link

Compatibility with User Meta fields #1

Open daandegroot123 opened 3 years ago

daandegroot123 commented 3 years ago

I have tried implementing this plugin on a website in order to combine 3 separate form fields into one meta field. My form and therefore meta field are related to a user, so they aren't post_meta but user_meta. Simply switching this in my code doesn't work, so is there any way I can get this to work?

This is my current snippet of code (straat, plaats, postcode and land are the name of the form fields and volledig-adres is the name of my user meta field):

add_filter( 'jet-engine-extend-form-actions/config', function() {
   return array(
    627 => array (
        'straat' => array(
            'prop' => 'user_meta',
            'key'  => 'volledig-adres',
        ),
        'plaats' => array(
            'prop' => 'user_meta',
            'key'  => 'volledig-adres',
        ),
        'postcode' => array(
            'prop' => 'user_meta',
            'key'  => 'volledig-adres',
        ),
        'land' => array(
            'prop' => 'user_meta',
            'key'  => 'volledig-adres',
        ),
    )
   );
} );
daandegroot123 commented 3 years ago

I tried adding this myself but now I get the feeling the plugin is not working at all. Console logging anywhere in the jet-engine-extend-form-action.php doesn't show me anything. I tried to add user_meta by copying most of the post_meta settings:

These lines were added: $user_input = array(); beneath the other array initializers.

case 'user_meta':

    if ( ! empty( $data['key'] ) ) {

            $value = $notifications->data[ $field ];
        $value = $this->prepare_value( $value, $data );

        if ( ! empty( $user_input[ $data['key'] ] ) ) {
            $user_input[ $data['key'] ] .= $value;
        } else {
            $user_input[ $data['key'] ] = $value;
        }

    }

break;

Beneath the other cases in the switch.

if ( ! empty( $user_input ) ) {
    foreach ( $user_input as $key => $value ) {
        update_user_meta( wp_get_current_user(), $key, $value );
    }
}

Beneath the other if-statements with similar contents.

A more detailed explanation about this plugin would be helpful as this could solve quite a few problems I've been running into with JetEngine Forms.

hamed-azimi commented 2 years ago

@daandegroot123 after almost 1 year you didn't get an answer yet, nor this is supported in JetFormBuilder itself?!

I also need this critically and the JFB is very limited in the case of creating complex forms. It works up to some level but when you want to take it to the next step, you hit a solid wall and can't really do anything, and the support unfortunately is very slow.

@MjHead any chance to make it work for user meta? (preferably built-in in JFB, but if not, at least on this add-on)

I have 2 fields in my form as an example, which one of them is Country Code, and the other is Phone Number, and on submit, I want to mix them and update 1 single user meta field.

I've tried this and it didn't work:

add_filter( 'jet-engine-extend-form-actions/config', function() {
    return array(
        76321 => array(
            'account_details_country_calling_code' => array(
                'prop' => 'post_meta',
                'key'  => 'shipping_phone',
            ),
            'account_details_phone_number' => array(
                'prop' => 'post_meta',
                'key'  => 'shipping_phone',
            ),
        ),
    );
} );