因此,我在一页上有一个表单,它正在提交给admin-post.php
, 然后在函数中有一个函数。正在处理表单的php。它将输入字段数据存储到数据库中,然后将用户重定向到另一个页面。它将信息存储在数据库中,但不重定向。问题是它说
无法修改标题信息-标题已发送
代码:
<form action="<?php echo esc_url( admin_url(\'admin-post.php\') ); ?>" method="post">
<input id="user_name" type="text" name="yourname" placeholder="Name" class="form-control">
<input id="user_email" type="text" name="email" placeholder="Email" class="form-control">
<button id="button" type="button" name="submit">Go</button>
<input type="submit" value="submit" name="submit" class="btn btn-success">
<input type="hidden" name="action" value="login_form">
</form>
功能。php
function prefix_send_email_to_admin() {
/**
* At this point, $_GET/$_POST variable are available
*
* We can do our normal processing here
*/
// Sanitize the POST field
// Generate email content
// Send to appropriate email
function my_print_error(){
global $wpdb;
if($wpdb->last_error !== \'\') :
$str = htmlspecialchars( $wpdb->last_result, ENT_QUOTES );
$query = htmlspecialchars( $wpdb->last_query, ENT_QUOTES );
print "<div id=\'error\'>
<p class=\'wpdberror\'><strong>WordPress database error:</strong> [$str]<br />
<code>$query</code></p>
</div>";
endif;
}
if (isset($_POST[\'submit\'])) {
global $wpdb;
$wpdb->show_errors();
$table = \'username\';
$data = array(
\'name\' => $_POST[\'yourname\']
);
$success=$wpdb->insert( $table, $data );
if($success){
echo \'data has been save\' ;
wp_redirect("http://example.design/projects/webdev/wordpress_nepal/");
exit;
}
else {
my_print_error();
}
}
// wp_redirect("http://example.design/projects/webdev/wordpress_nepal/");
}
add_action( \'wp_loaded\', \'prefix_send_email_to_admin\' );
我两个都试过了,
wp_loaded
谷歌搜索和我的原创
admin_post_nopriv_login_form
但这没有帮助。