我不确定是什么导致gravity forms$entry和$form parameters返回1。
这是我的班级。
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();
在提交表单后的错误日志中,我在日志文件中获得以下内容:
[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
重力模板版本=2.4.22
WordPress版本=5.6.2
PHP v.7.4
任何帮助都将不胜感激-谢谢!
最合适的回答,由SO网友:Pat J 整理而成
这不是重力形式,而是ob_end_clean()
, 它只是删除缓冲区并返回布尔值。(在这种情况下,true
, 可以表示为1
.)
是否有迫切的理由使用ob_*
功能?如果代码是这样的,那么它的可读性(和可预测性)会更高。
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 ) );
}
。。。使用
print_r()
而不是
var_dump()
.