Action
uncanny-automator-pro
gform_entry_created
Fires after a new Gravity Forms entry is successfully created and saved to the database.
add_action( 'gform_entry_created', $callback, 10, 2 );
Description
Fires after a Gravity Forms entry is successfully created and saved to the database. Developers can use this hook to perform custom actions immediately after entry creation, such as sending notifications, updating other systems, or modifying the entry data before further processing. It receives the `$entry` object and the `$form` object as parameters.
Usage
add_action( 'gform_entry_created', 'your_function_name', 10, 2 );
Parameters
-
$entry(mixed) - This parameter contains the Gravity Forms entry object that has just been created.
-
$form(mixed) - This parameter contains the Gravity Forms entry object that was just created.
Examples
add_action( 'gform_entry_created', 'my_custom_gform_entry_created_handler', 10, 2 );
/**
* Example handler for the gform_entry_created action hook.
* This function is triggered after a new Gravity Forms entry is created.
*
* @param array $entry The entry object.
* @param array $form The form object.
*/
function my_custom_gform_entry_created_handler( $entry, $form ) {
// For example, let's log the entry ID and form title to the WordPress debug log.
error_log( sprintf( 'Gravity Forms Entry Created: Entry ID %d for Form "%s" (Form ID: %d)', $entry['id'], $form['title'], $form['id'] ) );
// You could also use this hook to:
// - Update a custom post type based on entry data.
// - Send an email notification to a specific user.
// - Add the user to a mailing list.
// - Trigger an external API call.
// Example: If the form ID is 5, send a Slack notification.
if ( 5 === $form['id'] ) {
$slack_message = sprintf(
"New Gravity Forms Submission!nForm: %snEntry ID: %dnEntry URL: %s",
$form['title'],
$entry['id'],
gf_apply_filters( 'gform_entry_link', '', $entry['id'], $form['id'] ) // Use GFAPI or GF helper for URL
);
// Replace with your actual Slack webhook URL and logic
// wp_remote_post( 'YOUR_SLACK_WEBHOOK_URL', array(
// 'body' => json_encode( array( 'text' => $slack_message ) ),
// ) );
}
// Example: If a specific field (e.g., field ID 3) has a certain value, update a user meta.
if ( isset( $entry[3] ) && 'premium' === $entry[3] ) {
$user_id = get_current_user_id(); // Or retrieve user ID from another field if available
if ( $user_id ) {
update_user_meta( $user_id, 'gravity_forms_subscription_level', 'premium' );
}
}
}
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
uncanny-automator-pro/src/integrations/gravity-forms/actions/gf-createentry.php:162
public function process_action( $user_id, $action_data, $recipe_id, $args, $parsed ) {
$form_id = Automator()->parse->text( $action_data['meta'][ $this->action_meta ], $recipe_id, $user_id, $args );
$fields = json_decode( $action_data['meta']['GF_FIELDS'] ?? '[]' );
$gfrom_input_values = $this->gf->helpers->format_input_values( $fields, $recipe_id, $user_id, $args );
// Format time fields if present
$gfrom_input_values = $this->time_handler->format_time_fields( $gfrom_input_values, $form_id );
$gfrom_input_values['form_id'] = absint( $form_id );
$gfrom_input_values['created_by'] = $user_id;
$entry_id = GFAPI::add_entry( $gfrom_input_values );
if ( is_wp_error( $entry_id ) ) {
$error_message = $entry_id->get_error_message();
throw new Exception( esc_html( $error_message ) );
}
// Get the entry and form objects
$entry = GFAPI::get_entry( $entry_id );
$form = GFAPI::get_form( $entry['form_id'] );
// Manually trigger the form submission action
do_action( 'gform_after_submission', $entry, $form );
// Trigger other actions if necessary (e.g., for third-party integrations)
do_action( 'gform_entry_created', $entry, $form );
do_action( 'gform_post_add_entry', $entry, $form );
$this->hydrate_tokens(
array(
'ENTRY_ID' => $entry_id,
'ENTRY_URL' => $this->gf->helpers->get_entry_url( $entry_id, $form_id ),
)
);
return true;
}