Using Gravity Forms ‘gform_preview_footer’ PHP action

The gform_preview_footer action is triggered when the footer of the form preview page loads, allowing further actions to be done.

Usage

add_action('gform_preview_footer', 'my_custom_function', 10, 1);

Parameters

  • $id (int) – The ID of the current form being previewed.

More information

See Gravity Forms Docs: gform_preview_footer

This action hook is located in preview.php.

Examples

Add custom JavaScript code to the footer of the form preview page.

function add_custom_js_to_preview_footer() {
  // Custom JavaScript code
  echo "<script>
    console.log('Form preview footer loaded.');
  </script>";
}
add_action('gform_preview_footer', 'add_custom_js_to_preview_footer', 10, 1);

Display a custom message based on form ID

Display a custom message in the form preview footer based on the form ID.

function display_custom_message($id) {
  if ($id == 1) {
    echo "<p>This is a custom message for Form 1.</p>";
  } elseif ($id == 2) {
    echo "<p>This is a custom message for Form 2.</p>";
  }
}
add_action('gform_preview_footer', 'display_custom_message', 10, 1);

Add custom CSS styles to the footer of the form preview page.

function add_custom_css_to_preview_footer() {
  // Custom CSS styles
  echo "<style>
    body { background-color: lightblue; }
  </style>";
}
add_action('gform_preview_footer', 'add_custom_css_to_preview_footer', 10, 1);

Display the form ID in the footer of the form preview page.

function display_form_id($id) {
  echo "<p>Form ID: {$id}</p>";
}
add_action('gform_preview_footer', 'display_form_id', 10, 1);

Add a custom button to the footer of the form preview page.

function add_custom_button_to_preview_footer() {
  echo '<button type="button" onclick="alert(\'Custom Button Clicked!\')">Custom Button</button>';
}
add_action('gform_preview_footer', 'add_custom_button_to_preview_footer', 10, 1);