The gform_view action allows you to perform additional actions based on the current form view in Gravity Forms.
Usage
add_action('gform_view', 'your_function_name');
Parameters
- $view (string) – The current form view. Some common views include “entries”, “entry”, “notification”, and “settings”.
- $id (string) – The ID of the form being viewed.
More information
See Gravity Forms Docs: gform_view
Examples
Display a custom message on the “entries” view
This example shows how to display a custom message when the “entries” view is accessed.
add_action('gform_view', 'display_custom_message', 10, 2); function display_custom_message($view, $id) { if ($view == 'entries') { echo 'Welcome to the entries view!'; } }
Redirect users from the “settings” view
This example demonstrates how to redirect users away from the “settings” view of a specific form.
add_action('gform_view', 'redirect_from_settings', 10, 2); function redirect_from_settings($view, $id) { if ($view == 'settings' && $id == '1') { wp_redirect(home_url()); exit; } }
Add custom CSS class to the “notification” view
This example adds a custom CSS class to the body tag when the “notification” view is accessed.
add_action('gform_view', 'add_custom_css_class', 10, 2); function add_custom_css_class($view, $id) { if ($view == 'notification') { add_filter('admin_body_class', function($classes) { return "$classes my-custom-class"; }); } }
Log the form view
This example logs the form view and ID whenever a form view is accessed.
add_action('gform_view', 'log_form_view', 10, 2); function log_form_view($view, $id) { error_log("Form view: $view, Form ID: $id"); }
Display a custom message based on the form ID
This example shows how to display a custom message when a specific form is accessed in any view.
add_action('gform_view', 'display_custom_message_based_on_id', 10, 2); function display_custom_message_based_on_id($view, $id) { if ($id == '2') { echo "You are viewing form ID 2."; } }