php - 如何使用插件钩子使用 var_dump() 或 printr() 从 Contact Form 7 表单中显示提交的值
问题描述
我想看看“$name”变量里面有什么,我该怎么做?
add_action("wpcf7_before_send_mail", "wpcf7_do_something_else");
function wpcf7_do_something_else( &$WPCF7_ContactForm ) {
$name = $WPCF7_ContactForm->posted_data['your-name'];
var_dump($name);
}
解决方案
var_dump()
CF7使用AJAX提交表单,普通方式是看不到的。所以通过 PHP 你可以使用 WordPress的debug.log文件。Iside “wp-config.php” 而不是define('WP_DEBUG', false);
写:
// Enable WP_DEBUG mode
define( 'WP_DEBUG', true );
// Enable Debug logging to the /wp-content/debug.log file
define( 'WP_DEBUG_LOG', true );
// Disable display of errors and warnings
define( 'WP_DEBUG_DISPLAY', false );
@ini_set( 'display_errors', 0 );
然后:
add_action("wpcf7_before_send_mail", "wpcf7_do_something_else");
function wpcf7_do_something_else( &$WPCF7_ContactForm ) {
$name = $WPCF7_ContactForm->posted_data['your-name'];
ob_start(); // start buffer capture
var_dump($name);
$contents = ob_get_contents(); // put the buffer into a variable
ob_end_clean(); // end capture
error_log($contents); // write the log file
}
作为选项,您可以通过CF7 DOM 事件
示例在前端使用 JS 执行此
操作 - 当您的表单提交时:
<script>
document.addEventListener( 'wpcf7submit', function( event ) {
var inputs = event.detail.inputs;
for ( var i = 0; i < inputs.length; i++ ) {
if ( 'your-name' == inputs[i].name ) {
alert( inputs[i].value );
/*
or in console:
console.log( inputs[i].value );
*/
break;
}
}
}, false );
</script>
推荐阅读
- wpf - 如何将当前节点对象传递给wpf中telerik RadtreeviewItem中的命令
- html - 仅当另一个元素没有子元素时,如何在Angular 7中显示一个元素
- visual-studio-code - 发布 VSCode 扩展后缺少 SVG 图标
- twilio - 即使升级后也无法从 twilio 向未经验证的用户发送 otp 短信
- amazon-web-services - 允许从特定账户的所有 EC2 实例访问 S3 存储桶
- ldap - 身份验证/授权提供商:为 1 天的项目选择哪一个?
- php - 如何使用php对数据库中的列求和
- r - 如何将字符串向量映射为函数的参数?
- mysql - MySQL 选择 id from to 并排除开始和结束 id
- rstudio - 包被存储在临时文件中