Question

I am using Wordpress and modifying a function to update user metadata when someone fills out a Gravity Form. The metadata I want updated is custom profile information. I update the data fine from the back end but cannot do it through the form.

I can't really see where I have gone wrong.

function GF_setup_actions_filters() {
        $_gf_edit_profile_id =  RGFormsModel::get_form_id('25');
        add_action('gform_after_submission_25' . $_gf_edit_profile_id, 'GF_update_profile', 100, 2); }

function GF_get_profile_fields() {
        $_fields['share_a_little'] = array ( 'gf_index' => '4', 'wp_meta' => 'share_a_little' );   
        return $_fields; }

function GF_update_profile($entry, $form) {
   global $wpdb;

   if (!is_user_logged_in()) {
      wp_redirect(home_url());
      exit();
   }


   $_user_id = get_current_user_id();   
   $_user = new stdClass();
   $_user->ID = (int) $_user_id;
   $_userdata = get_user_meta($_user_id);
   $_user->user_login = $wpdb->escape($_userdata->user_login);

   $gf_fields = GF_get_profile_fields();

   $share_a_little = $entry[$gf_fields['share_a_little']['4']];
   update_user_meta($_user->ID, 'share_a_little', $share_a_little);
}
Was it helpful?

Solution

This part is wrong.

$_gf_edit_profile_id =  RGFormsModel::get_form_id('25');
add_action('gform_after_submission_25' . $_gf_edit_profile_id, 'GF_update_profile', 100, 2); }

If your Form ID is 25, and the form isn't named 25. The lines should be replaced with:

 add_action('gform_after_submission_25', 'GF_update_profile', 100, 2); }

If the from is called 25 and you don;t know the ID the lines should be:

$_gf_edit_profile_id =  RGFormsModel::get_form_id('25');
add_action('gform_after_submission_' . $_gf_edit_profile_id, 'GF_update_profile', 100, 2); }

The code looks very similar to the article I wrote a while back on updating the User Profile using Gravity Forms. You can read it here with the explanation of the code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top