0

I have made a admin page linked to a Settings -> submenu_item. This page looks like this:

http://movahon.dev/wp-admin/options-general.php?page=miama-google-recaptcha%2Fmiama-google-recaptcha.php

On this page, I have a form which I want to submit to this same page. How can I do this? It is a bit of complication, since this page already has GET parameters in its URL, in form of the query string. So, I couldn't POST or GET to it easy, because it just redirects to the base URL, which is:

http://movahon.dev/wp-admin/options-general.php

I tried putting these in action, and none worked for me:

action="" 
action="#" 
action="<?php echo($_SERVER["PHP_SELF"]);?>"
2

While WP is a little weak about working with forms in general, there are some loose conventions that can help keep things organized.

For POST forms there is a dedicated wp-admin/admin-post.php endpoint, which meant for just that and works similarly to better known admin-ajax.php.

Unless you have good reasons to organize it otherwise I would recommend just to use it for form processing. After you are done you can get back to your page with something like wp_safe_redirect( wp_get_referer() ); die;.

1
  • +1 Almost a decade & I never knew about admin-post.php May 24 '17 at 17:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.