Update table using gform_after_update_entry

I need to send an update back to a table but am returning empty values on my test setup. Do I have something wrong in my code?

Target Table
RiderPK (varchar) → Primary Key
Fullname (varchar)
TeamName (varchar)

Form ID: 80
RiderPK is in field 35
TeamName is in field 14

Here’s my code:

add_action("gform_after_update_entry_80", "update_team", 10, 2);
function update_team($form, $entry_id){
    global $wpdb;
		  $TeamName = $entry_id["14"];
		  $RiderPK = $entry_id["35"];
$wpdb->update( 'TestTeamTable', array( 'TeamName' => $TeamName), array( 'RiderPK' =>  $RIderPK,));

If I hardcode the PK field, I am still getting a blank value in $TeamName.

My INSERT is working:

add_action("gform_after_submission_80", "input_fields", 10, 2);
function input_fields($entry, $form){
    global $wpdb;
		$TeamName = $entry["14"];
		$FullName = $entry["26"];
		$RiderPK = $entry["35"];
$SQL = "INSERT INTO TestTeamTable ( RiderPK, TeamName, FullName) VALUES ( '$RiderPK', '$TeamName', '$FullName' )";
 $wpdb->query($SQL);
}

$entry_id is just an integer, the ID of the entry that was updated. The $entry array that contains all the field values isn’t passed to the gform_after_update_entry hook.

You’ll need to update the update_team function to get the entry before you define the $TeamName and $RiderPK variables, e.g.

$entry = GFAPI::get_entry( $entry_id );
$TeamName = rgar( $entry, '14' );
$RiderPK = rgar( $entry, '35' );
1 Like

Ah! I see that now! Thank you for your help. It’s working for me with the updated information.

1 Like

Okay next (related) question. If I delete the entry, I need to send an update back again to revert the team member status back to “unassigned”. I’m not able to get this one working. Can you spot my issue?

***/Revert member back to unassigned after deletion from a team./***
add_action( "gform_delete_entry_18", "revertback", 10, 1 );
Function revertback($form, $entry_id){
    global $wpdb;
		  $entry = GFAPI::get_entry( $entry_id);
		 $RiderPK = $entry["35"];
		 $PriorStat = $entry["36"];
$wpdb->update( 'RegisteredMembers', array( 'Program' => 'Unassigned', 'TeamStatus' => $PriorStat), array( 'submission_id' => $RiderPK,));

I figured that out too. It’s magic what happens when you log a ticket.

/***Revert member back to unassigned after deletion from a team.***/
add_action( "gform_delete_entry", "revertback", 10, 1 );
Function revertback($entry_id){
    global $wpdb;
		  $entry = GFAPI::get_entry( $entry_id);
		 $RiderPK = $entry["35"];
		 $PriorStat = $entry["36"];
$wpdb->update( 'RegisteredMembers', array( 'Program' => 'Unassigned', 'TeamStatus' => $PriorStat), array( 'submission_id' => $RiderPK,));

}

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.