admin管理员组文章数量:1289516
I'm using admin-post.php to handle a form submission on the admin side of a WordPress plugin I'm building. I have my form set up in a function like this:
function display_charge_customer_input() {
global $stripe_options;
$charge_amount_btn = "Charge $" . $stripe_options['amount_to_charge'];
?>
<h3 class="title"><?php _e('Charge Customer', 'kite_stripe'); ?></h3>
<form action="<?php echo esc_url( admin_url('admin-post.php') ); ?>" method="post">
<input type="hidden" name="action" value="charge_customer_data"/>
<table class="form-table">
<tbody>
<tr valign="top">
<th scope="row" valign="top">
<?php _e('Charge Customer', 'kite_stripe'); ?>
</th>
<td>
<input id="charge_customer_input" name="charge_customer_input" type="text" class="regular-text" value="Customer Id"/>
<label class="description" for="charge_customer_input"><?php _e('Paste the customer id of the person you\'d like to charge.', 'kite_stripe'); ?></label>
</td>
</tr>
</tbody>
</table>
<p class="submit_charge">
<input type="submit" class="button-primary" name = "charge_submit" value="<?php _e($charge_amount_btn, 'kite_domain') ?>" />
</p>
</form>
<?php
}
I'm calling the function from another file to have it show up on the admin page. That is all working fine.
Now here's my code that is supposed to handle the form request:
add_action( 'admin_post_charge_customer_data', 'charge_customer_data' );
add_action( 'admin_post_nopriv_charge_customer_data', 'charge_customer_data' );
function charge_customer_data() {
if (isset($_POST['charge_submit'])){
$url = "http://localhost:8888/wp-admin/admin.php?page=user-list-table.php";
wp_redirect($url);
exit;
}
}
I'm going to have the form save user input as well but I just wanted to get the redirect working first. I've tried reading everything I could on Stack Overflow and Google searches and I still can't figure out where I'm going wrong. I'm thinking maybe my if(isset($_POST['charge_submit']))
code just isn't working when the submit button isn't clicked but I don't see why it wouldn't.
I'm pretty new to all this so any help would be appreciated. Thank you!
I'm using admin-post.php to handle a form submission on the admin side of a WordPress plugin I'm building. I have my form set up in a function like this:
function display_charge_customer_input() {
global $stripe_options;
$charge_amount_btn = "Charge $" . $stripe_options['amount_to_charge'];
?>
<h3 class="title"><?php _e('Charge Customer', 'kite_stripe'); ?></h3>
<form action="<?php echo esc_url( admin_url('admin-post.php') ); ?>" method="post">
<input type="hidden" name="action" value="charge_customer_data"/>
<table class="form-table">
<tbody>
<tr valign="top">
<th scope="row" valign="top">
<?php _e('Charge Customer', 'kite_stripe'); ?>
</th>
<td>
<input id="charge_customer_input" name="charge_customer_input" type="text" class="regular-text" value="Customer Id"/>
<label class="description" for="charge_customer_input"><?php _e('Paste the customer id of the person you\'d like to charge.', 'kite_stripe'); ?></label>
</td>
</tr>
</tbody>
</table>
<p class="submit_charge">
<input type="submit" class="button-primary" name = "charge_submit" value="<?php _e($charge_amount_btn, 'kite_domain') ?>" />
</p>
</form>
<?php
}
I'm calling the function from another file to have it show up on the admin page. That is all working fine.
Now here's my code that is supposed to handle the form request:
add_action( 'admin_post_charge_customer_data', 'charge_customer_data' );
add_action( 'admin_post_nopriv_charge_customer_data', 'charge_customer_data' );
function charge_customer_data() {
if (isset($_POST['charge_submit'])){
$url = "http://localhost:8888/wp-admin/admin.php?page=user-list-table.php";
wp_redirect($url);
exit;
}
}
I'm going to have the form save user input as well but I just wanted to get the redirect working first. I've tried reading everything I could on Stack Overflow and Google searches and I still can't figure out where I'm going wrong. I'm thinking maybe my if(isset($_POST['charge_submit']))
code just isn't working when the submit button isn't clicked but I don't see why it wouldn't.
I'm pretty new to all this so any help would be appreciated. Thank you!
Share Improve this question asked Apr 18, 2018 at 15:47 ColtvantColtvant 1871 silver badge10 bronze badges 4 |1 Answer
Reset to default 1So I figured this out...I realized I was adding my charge_customer_data()
function within a class and that it was never being called. I created a new file in my plugin directory separate from the class, added the function, and it worked.
本文标签: plugin developmentUsing adminpostphp for admin form but it directs me to adminpostphp white screen
版权声明:本文标题:plugin development - Using admin-post.php for admin form but it directs me to admin-post.php white screen 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741477822a2380990.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
var_dump
anywhere it's still not showing up because when I hit submit, it takes me right to the admin-post.php white page. I tried testing it within the form/function but it's the same issue. – Coltvant Commented Apr 18, 2018 at 16:18charge_customer_data()
into functions.php it will work right. However, I would really like to keep all my functions in my plugin directory...is that possible? – Coltvant Commented Apr 18, 2018 at 16:31