Using Gravity Forms “gform_after_submission” filter hook

I want to update the post and edit the value of an existing field with a sequence number after the entry has been created at gform_after_submission hook.

The requirement is to update a single field value in the same post and then update the post. I I found this documentation but not that helpful.

Read More

And tried the following but it’s updating all the fields:

add_filter( "gform_save_field_value", "set_field_value", 10, 4 ); 

function set_field_value( $value, $lead, $field, $form ){ 
    if( $form['id'] != 1 || $field['id'] != 19 ) 
        return; 

    $value = "xxx"; 
    return $value; 
}

Related posts

Leave a Reply

2 comments

  1. I think your logic is a bit off I would check IF it IS the right field rather than if it’s not and do something like this:

        add_filter( "gform_save_field_value", "nifty_set_field_value", 10, 4 ); 
    
        function nifty_set_field_value( $value, $lead, $field, $form ){ 
        //make sure we are on form 1 AND field 19
        if( $form['id'] == 1 &&  $field['id'] == 19 ){
            //set value
            $value = "xxx";
            //return
            return $value; 
        } 
       //not our field, that's okay just return the normal value
       else {return $value;  }
    

    You may be able to do it without the else and just return value once but if I remember right (and the docs show) both are needed.

    Or you could do it with your current code:

        add_filter( "gform_save_field_value", "nifty_set_field_value", 10, 4 ); 
    
    function nifty_set_field_value( $value, $lead, $field, $form ){ 
        if( $form['id'] != 1 || $field['id'] != 19 ) {
            return $value; 
    }
    $value = "xxx"; 
    return $value; 
    

    }

    just make sure you return the value not just return the function

    Here is a link to the correct docs page Also Gravity Forms has a support form of its own for users who have paid for the product. Lastly, Check out their example pastie

  2. I solved the issue using the below code:

    add_filter("gform_get_input_value", "update_field", 10, 4);
    
        function update_field($value, $lead, $field, $input_id){
            if($lead["form_id"] == 1 && $field["id"] == 19)
                return 'xxx';
            else
                return $value;
        }
    
        add_filter("gform_save_field_value", "save_field_value", 10, 4);
    
        function save_field_value($value, $lead, $field, $form){
            if($lead["form_id"] == 1 && $field["id"] == 19)
                return 'xxx';
            else
                return $value;
        }