$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>php - How to handle a custom form in wordpress to submit to another page?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

php - How to handle a custom form in wordpress to submit to another page?

matteradmin9PV0评论

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 badges
Add a comment  | 

1 Answer 1

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.

Post a comment

comment list (0)

  1. No comments so far