Update entry with a different form entries in gravity forms

i need to update a gravity form student information entries. my problem is that i registered student in two different forms. now i want to update the student information and i can’t. i’m using this guide.

forms structures:

  • form 1: regular registration.
  • form 2: registration in middle of the course.
  • form 3: this is the forms that is on /edit-student/.

form 3 is populated with the entry data set as default values to each field:

$edit_form["fields"][1]["defaultValue"] = $cvalue["21"];

but the entries are not being updated and i feels like it’s really bed code (im a new programmer. this is my code:

add_action("gform_pre_submission_15", "edit_form_pre_submission_handler");
function edit_form_pre_submission_handler($form)
{
    // //Get original entry id
    $r = 5;
    $a = 12;
    $form_5 = GFAPI::get_entries($r);
    $form_12 = GFAPI::get_entries($a);

    $student_id = $form["fields"][9]["defaultValue"];
    if (is_array($student_id))
        $marged_entries = array_merge($form_5, $form_12);
    if (is_array($form)) {
        if (is_array($entry)) {
            foreach ($marged_entries as  $entry) {
                if ($entry["post_id"] == $student_id) {
                    $entry_id = $entry['id'];
                    $editentry = GFAPI::get_entry($entry_id);
                    // save values
                    $editentry["21"] = $_POST["input_11"];
                    //  parent Last name
                    $editentry["20"] = $_POST["input_13"];
                    //  student first name
                    $editentry["26"] = $_POST["input_14"];
                    //  student Last name
                    $editentry["25"] = $_POST["input_15"];
                    // email and post title
                    $editentry["22"] = $_POST["input_6"];
                    // Address
                    $editentry["23"] = $_POST["input_8"];
                    //  Student Age 
                    $editentry["27"] = $_POST["input_10"];
                    //  Student Phone 
                    $editentry["24"] = $_POST["input_5"];
                    //   update entry
                    $updateit = GFAPI::update_entry($editentry);
                    // die();
                    if (is_wp_error($updateit)) {
                        echo "Error.";
                    } else {
                        //success
                        echo 'student updated';
                    }
                }
            }
        }
    }
}

question: 1) is there a better way to update GF entries with entries from another form? 2) way when i remove the comment from die() the site get stoke? i cant stom form 3 from getting submitted with out this function. 3) way the form is not getting updated?. on its on all of the values are working.

Hi Amir, Populate Anything is a great way to populate data from existing entires into a form post. Once populated, you can update an existing entry by setting the entry ID to be updated via this filter:

You’ll see that the code required is much simpler.

If you decide to go this route and have any questions, we’ll be happy to help you via Gravity Perks support.