admin管理员组文章数量:1122832
In my case I have to submit form on same file which is a class without using any javascript or hook, the form action is action="<?php echo $_SERVER['PHP_SELF']; ?>"
. It is submitting the form but redirecting to the main page of the site. If the page link is /
and the form is on this link, after submitting form the url should be /?taskname=abc
but it is redirecting to the main site page like this /?taskname=abc
. What I am missing here
class tasks{
function search_form(){
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="GET" >
<input type='text' name='taskname' >
</form>
}
function search_form_submit(){
echo $_GET['taskname'];
}
}
$tasks_obj = new tasks();
if($_SERVER['REQUEST_METHOD'] == 'GET') {
$tasks_obj->search_form_submit();
}
In my case I have to submit form on same file which is a class without using any javascript or hook, the form action is action="<?php echo $_SERVER['PHP_SELF']; ?>"
. It is submitting the form but redirecting to the main page of the site. If the page link is http://sitename.com/my-link/
and the form is on this link, after submitting form the url should be http://sitename.com/my-link/?taskname=abc
but it is redirecting to the main site page like this http://sitename.com/?taskname=abc
. What I am missing here
class tasks{
function search_form(){
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="GET" >
<input type='text' name='taskname' >
</form>
}
function search_form_submit(){
echo $_GET['taskname'];
}
}
$tasks_obj = new tasks();
if($_SERVER['REQUEST_METHOD'] == 'GET') {
$tasks_obj->search_form_submit();
}
Share
Improve this question
asked Oct 24, 2017 at 6:58
mohsinmohsin
1772 silver badges9 bronze badges
3
|
1 Answer
Reset to default 0If your form is embedded in a shortcode or some other front end form, I would post to the permalink for the page. That's more reliable than using action="" in my experience. Then output something on that page to acknowledge the submission or show an error.
$global $post;
printf('<form method="post" action="%s">',get_permalink($post->ID));
or in for a form on the admin side:
printf('<form method="post" action="%s">',admin_url('admin.php?page=custom_form'));
Within admin_url, include the portion of the page url that comes after wp-admin/
本文标签: plugin developmentHow to Maintain url on form submit
版权声明:本文标题:plugin development - How to Maintain url on form submit 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736287775a1927954.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
action=""
attribute will always post to the current URL – Z. Zlatev Commented Oct 24, 2017 at 7:04