I’m not sure what’s causing gravity forms $entry and $form parameters to return 1.
Here is my class.
namespace GrvityFormsIntegrationDataTools;
ini_set( 'error_log', WP_CONTENT_DIR . '/debug.log' );
defined( 'ABSPATH' ) or die( 'No direct access!' );
class GravityFormService {
public function __construct() {
/**
* I've also tried this without the init hook with the same results
*/
add_action('init', function() {
add_action( 'gform_after_submission', array($this, 'collectGFData'), 10, 2 );
});
} // end construct
public function collectGFData($entry, $form ) {
error_log("form was submitted");
ob_start();
var_dump($entry);
$entryTesting = ob_end_clean();
error_log("entry was $entryTesting");
ob_start();
var_dump($form);
$formTesting = ob_end_clean();
error_log("form was $formTesting");
$formID = rgar( $entry, 'form_id' );
$dateCreated = rgar( $entry, 'date_created' );
ob_start();
var_dump($dateCreated);
$dateCreatedTesting = ob_end_clean();
error_log("date created testing was $dateCreatedTesting");
ob_start();
var_dump($formID);
$formIDTesting = ob_end_clean();
error_log("form id testing was $formIDTesting");
} // end collectGFData
}
$gformService = new GravityFormService();
In my error log after submitting the form, I get the following in my log file:
[27-Feb-2021 20:17:02 UTC] form was submitted [27-Feb-2021 20:17:02 UTC] entry was 1 [27-Feb-2021 20:17:02 UTC] form was 1 [27-Feb-2021 20:17:02 UTC] date created testing was 1 [27-Feb-2021 20:17:02 UTC] form id testing was 1 [27-Feb-2021 20:17:02 UTC] confirmation number testing was 1
Gravity forms version = 2.4.22
WordPress version = 5.6.2
PHP v. 7.4
Any help would be greatly appreciated – thanks!
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
It’s not Gravity Forms, it’s ob_end_clean(), which just deletes the buffer and returns a boolean value. (In this case, true, which is getting expressed as 1.)
Is there a pressing reason to use the ob_* functions? The code would be more readable (and predictable) if it was something like this.
public function collectGFData($entry, $form ) {
error_log("form was submitted");
error_log("entry was " . print_r( $entry. 1) );
error_log("form was " . print_r( $form, 1 ) );
$formID = rgar( $entry, 'form_id' );
$dateCreated = rgar( $entry, 'date_created' );
error_log("date created testing was " . print_r( $dateCreated, 1 ) );
error_log("form id testing was " . print_r( $formID, 1 ) );
}
…using print_r() instead of var_dump().
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0