我正在开发一个Wordpress插件,使用我的短代码中的操作获取$\\u帖子数据时遇到问题。我正在解析的表单位于我添加了短代码的页面上。
以下是我得到的:
function wpd_post_parse() {
$string = \'wp hook: \' . var_dump($_POST) . "\\r\\n";
//$string = \'wp hook: first name: \' . $_POST["first_name"] . "\\r\\n";
//$string .= \'wp hook: last name: \' . $_POST["last_name"] . "\\r\\n";
//$string .= \'wp hook: email: \' . $_POST["email"] . "\\r\\n";
$fileName = dirname(__FILE__) . \'/log.txt\';
file_put_contents($fileName, $string, FILE_APPEND | LOCK_EX);
//file_put_contents($fileName, $string, FILE_APPEND);
/*
if (!empty($_POST)){
$string = \'wp hook: \' . var_dump($_POST) . "\\r\\n";
$fileName = dirname(__FILE__) . \'/log.txt\';
file_put_contents($fileName, $string, FILE_APPEND | LOCK_EX);
//file_put_contents($fileName, $string, FILE_APPEND);
}else{
$string = \'wp hook: POST empty\' . "\\r\\n";
$fileName = dirname(__FILE__) . \'/log.txt\';
file_put_contents($fileName, $string, FILE_APPEND | LOCK_EX);
}
*/
}
function mgc_init(){
$htmlStr = \'Hello World!\' . "\\r\\n";
$fileName = dirname(__FILE__) . \'/log.txt\';
file_put_contents($fileName, $htmlStr, FILE_APPEND | LOCK_EX);
//file_put_contents($fileName, $htmlStr, FILE_APPEND);
//Add hook to capture $_POST data
add_action( \'parse_request\', \'wpd_post_parse\' );
}
add_shortcode(\'mgc\',\'mgc_init\'); //put this shortcode [mgc] on page in Wordpress
UPDATE: 谢谢你迄今为止的帮助。我试图在表单提交中获取$\\u POST值(名字),但该值不在$\\u POST[“first\\u name”]内。打印到文件中的所有内容都是“wp hook:first name:”下面是代码的外观:
//Capture the $_POST data
function wpd_post_parse() {
//$string = \'wp hook: \' . var_dump($_POST) . "\\r\\n";
$string = \'wp hook: first name: \' . $_POST["first_name"] . "\\r\\n";
//$string .= \'wp hook: last name: \' . $_POST["last_name"] . "\\r\\n";
//$string .= \'wp hook: email: \' . $_POST["email"] . "\\r\\n";
$fileName = dirname(__FILE__) . \'/log.txt\';
file_put_contents($fileName, $string, FILE_APPEND | LOCK_EX);
//file_put_contents($fileName, $string, FILE_APPEND);
/*
if (!empty($_POST)){
$string = \'wp hook: \' . var_dump($_POST) . "\\r\\n";
$fileName = dirname(__FILE__) . \'/log.txt\';
file_put_contents($fileName, $string, FILE_APPEND | LOCK_EX);
//file_put_contents($fileName, $string, FILE_APPEND);
}else{
$string = \'wp hook: POST empty\' . "\\r\\n";
$fileName = dirname(__FILE__) . \'/log.txt\';
file_put_contents($fileName, $string, FILE_APPEND | LOCK_EX);
}
*/
//exit;
}
function mgc_init(){
$htmlStr = \'Hello World!\' . "\\r\\n";
$fileName = dirname(__FILE__) . \'/log.txt\';
file_put_contents($fileName, $htmlStr, FILE_APPEND | LOCK_EX);
//file_put_contents($fileName, $htmlStr, FILE_APPEND);
do_action( \'wpd_post_parse\' );
}
add_shortcode(\'mgc\',\'mgc_init\'); //put this shortcode [mgc] page in Wordpress
add_action( \'parse_request\', \'wpd_post_parse\' );