csuk1
csuk1

Reputation: 81

Gravity Form save to Database usermeta table

I have created the following wordpress function to save a form created in Gravity Forms to the usermeta database based on one I had working for CF7 but it isn't working, hopefully someone can see where I've made a mistake. It needs to update the current users fields.

add_action('gform_after_submission', 'input_fields', 10, 2);
function input_fields($entry, $form){

           $name = $entry['1'];
           $email = $entry['4'];

global $wpdb, $current_user;
$wpdb->insert(
'usermeta',
array(
'description' => $email,
'former_name' => $name
)
);
}

I've seen other examples which are pretty much identical so i'm a bit stuck.

Upvotes: 1

Views: 1218

Answers (2)

OguzKaganAslan
OguzKaganAslan

Reputation: 21

Semicolon sign ";" is missing at line 8 so this is right the answer. :)

add_action( 'gform_after_submission', 'input_fields', 10, 2 );
function input_fields( $entry, $form ) {

$name = $entry[1];
$email = $entry[4];

update_user_meta( get_current_user_id(), 'description', $email );
update_user_meta( get_current_user_id(), 'former_name', $name );

}

Upvotes: 0

Dave from Gravity Wiz
Dave from Gravity Wiz

Reputation: 2869

This should do the trick:

add_action( 'gform_after_submission', 'input_fields', 10, 2 );
function input_fields( $entry, $form ) {

    $name = $entry[1];
    $email = $entry[4];

    update_user_meta( get_current_user_id(), 'description', $email );
    update_user_meta( get_current_user_id(), 'former_name', $name )

}

Alternately, I'd recommend upgrading to a Developer license and getting access to the User Registration add-on which would do this even more easily. :)

Upvotes: 1

Related Questions