admin管理员组文章数量:1130349
I know in PHP I can just put action equal to random.php file and process the data there, but how in wordpress can I use already existing page with a custom template to submit a form to, so that after submitting a form on one page, user will be redirected to another page in wordpress with all his inputted credentials still available?
I know in PHP I can just put action equal to random.php file and process the data there, but how in wordpress can I use already existing page with a custom template to submit a form to, so that after submitting a form on one page, user will be redirected to another page in wordpress with all his inputted credentials still available?
Share Improve this question asked Nov 12, 2018 at 22:25 LimpulsLimpuls 3071 gold badge3 silver badges16 bronze badges1 Answer
Reset to default 6<form action="<?php echo esc_url( admin_url('admin-post.php') ); ?>" method="post">
<input type="hidden" name="action" value="your_action_name">
Add these in your form. Where admin-post.php will process your form. In that case based on the value of your_action_name that is provided by you, an action hook will get involved. Say for example if you add a hook like the following in functions.php of your theme or in your plugin
add_action( 'admin_post_nopriv_your_action_name', 'your_function_to_process_form' );
then for non logged in user
function your_function_to_process_form(){
// process your form here
}
will be called. From there you can process your form. For logged in user you need to rename your action to admin_post_your_action_name from admin_post_nopriv_your_action_name. Remember admin_post_ or admin_post_nopriv_ are available in admin-post.php to do_action appropriate action. Whatever you append at the end of admin_post_nopriv_ or admin_post_ will formulate a action hook. That needs to implemented by add_action(). If you pass contactform as a hidden action then your action hook will be either admin_post_nopriv_contactform or admin_post_contactform or both.
I know in PHP I can just put action equal to random.php file and process the data there, but how in wordpress can I use already existing page with a custom template to submit a form to, so that after submitting a form on one page, user will be redirected to another page in wordpress with all his inputted credentials still available?
I know in PHP I can just put action equal to random.php file and process the data there, but how in wordpress can I use already existing page with a custom template to submit a form to, so that after submitting a form on one page, user will be redirected to another page in wordpress with all his inputted credentials still available?
Share Improve this question asked Nov 12, 2018 at 22:25 LimpulsLimpuls 3071 gold badge3 silver badges16 bronze badges1 Answer
Reset to default 6<form action="<?php echo esc_url( admin_url('admin-post.php') ); ?>" method="post">
<input type="hidden" name="action" value="your_action_name">
Add these in your form. Where admin-post.php will process your form. In that case based on the value of your_action_name that is provided by you, an action hook will get involved. Say for example if you add a hook like the following in functions.php of your theme or in your plugin
add_action( 'admin_post_nopriv_your_action_name', 'your_function_to_process_form' );
then for non logged in user
function your_function_to_process_form(){
// process your form here
}
will be called. From there you can process your form. For logged in user you need to rename your action to admin_post_your_action_name from admin_post_nopriv_your_action_name. Remember admin_post_ or admin_post_nopriv_ are available in admin-post.php to do_action appropriate action. Whatever you append at the end of admin_post_nopriv_ or admin_post_ will formulate a action hook. That needs to implemented by add_action(). If you pass contactform as a hidden action then your action hook will be either admin_post_nopriv_contactform or admin_post_contactform or both.
本文标签: phpHow to handle a custom form in wordpress to submit to another page
版权声明:本文标题:php - How to handle a custom form in wordpress to submit to another page? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749187258a2329593.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论