Using Gravity Forms ‘gform_form_not_found_message’ PHP filter

The gform_form_not_found_message filter in Gravity Forms allows you to change the default form message, “Oops! We could not locate your form.”

Usage

add_filter('gform_form_not_found_message', 'your_function_name', 10, 2);

Parameters

  • $message (string) – The default form not found message.
  • $id (int) – The ID of the form attempted to be used.

More information

See Gravity Forms Docs: gform_form_not_found_message

Examples

Change the default message

Change the default form not found message.

add_filter('gform_form_not_found_message', 'change_message', 10, 2);
function change_message($message, $id) {
    return "We could not find the form with id " . $id;
}

Display a custom message with additional information

Show a custom message with additional information for admins.

add_filter('gform_form_not_found_message', 'custom_message_for_admin', 10, 2);
function custom_message_for_admin($message, $id) {
    if (current_user_can('manage_options')) {
        return "Admin, the form with id " . $id . " was not found. Please verify its existence.";
    } else {
        return "We could not find the requested form. Please try again later.";
    }
}

Display message in another language

Show the form not found message in Spanish.

add_filter('gform_form_not_found_message', 'spanish_message', 10, 2);
function spanish_message($message, $id) {
    return "¡Vaya! No pudimos encontrar su formulario.";
}

Add a link to the homepage in the not found message.

add_filter('gform_form_not_found_message', 'add_homepage_link', 10, 2);
function add_homepage_link($message, $id) {
    return "Oops! We could not locate your form. <a href='" . home_url() . "'>Go back to the homepage</a>.";
}

Display different messages based on form ID

Show a specific message for a particular form ID.

add_filter('gform_form_not_found_message', 'custom_message_for_specific_form', 10, 2);
function custom_message_for_specific_form($message, $id) {
    if ($id == 5) {
        return "The event registration form is no longer available. Please contact us for more information.";
    } else {
        return "We could not find the form with id " . $id;
    }
}