Getting following after form submission:
Warning: Undefined array key “page_number” in**/home/customer/www/bluegreyfootball.com/public_html/wp-content/plugins/gravityforms/form_display.phpon line787**
Getting following after form submission:
Warning: Undefined array key “page_number” in**/home/customer/www/bluegreyfootball.com/public_html/wp-content/plugins/gravityforms/form_display.phpon line787**
Hi Brent,
I’ve identified the cause of the following warning appearing after form submission:
Warning: Undefined array key "page_number" in .../gravityforms/form_display.php on line 787
This is a PHP 8.x compatibility issue in Gravity Forms where the code doesn’t fully check whether a value exists before accessing it. It does not affect form functionality, but the warning is noisy and may clutter your error logs.
Apply a hotfix via a must-use plugin (stops the warning immediately)
Create the file /wp-content/mu-plugins/gf-hotfix-page-number.php with the following content:
<?php
/**
* Plugin Name: GF Hotfix – Undefined array key page_number
* Description: Prevents PHP 8.x warning in GFFormDisplay::get_current_page()
* Version: 1.0
* Author: Faisal Ahammad
*/
add_filter( 'gform_pre_render', function( $form ) {
$form_id = absint( rgar( $form, 'id' ) );
if ( class_exists( 'GFFormDisplay' ) ) {
try {
$ref = new ReflectionProperty( 'GFFormDisplay', 'submission' );
$ref->setAccessible( true );
$submission = $ref->getValue();
if ( isset( $submission[ $form_id ] ) && ! isset( $submission[ $form_id ]['page_number'] ) ) {
$submission[ $form_id ]['page_number'] = 1;
$ref->setValue( null, $submission );
}
} catch ( Exception $e ) {
// Gracefully ignore if Reflection is unavailable.
}
}
return $form;
}, PHP_INT_MAX );
This hotfix ensures that self::$submission[$form_id] always has the page_number key set before it is accessed, preventing the warning. It works at runtime without modifying any Gravity Forms core files, so it won’t be overwritten when the plugin is updated.
Regarding the mu-plugins, they can be found here:
Give it a try, and let me know how that goes!