Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. add_action( 'template_redirect', 'wpse149613_form_process' );
  2.  
  3. function wpse149613_form_process(){
  4. if(!isset($_POST['submit'])) // assuming you're using POST and submit button name is 'submit'
  5. return;
  6.  
  7. // Validate the form, verify nonce
  8.  
  9. // process form
  10.  
  11. }
  12.  
  13. <form action="<?=admin_url( 'admin-post.php' ) ?>" method="POST">
  14. <!-- your inputs -->
  15. <input type="hidden" name="action" value="myplugin_mycustomaction"/>
  16. <input type="submit" value="Send"/>
  17. </form>
  18.  
  19. add_action( 'admin_post_nopriv_myplugin_mycustomaction',array( "class_that_owns_that_function", 'yourmethod' ) );
  20.  
  21. public function yourmethod()
  22. {
  23. // Do what you want with $_POST variables
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement