0

I'm not sure what's causing gravity forms $entry and $form parameters to return 1.

Here is my class.

namespace GrvityFormsIntegration\DataTools;

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!

1 Answer 1

2

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().

1
  • 1
    I switched editors, and my auto complete was using ob_end_clean(). I meant to use ob_get_clean(). ob_get_clean() has it working perfectly. Feb 28, 2021 at 0:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.