php 表单 动作 php self
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6862735/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
php form action php self
提问by Sasindu H
I have a php form like this.
我有一个这样的 php 表单。
<form name="form1" id="mainForm" method="post"enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF'];?>">
</form
In form action I want to use page name with parameters. like house.php?p_id=10111
. But $_SERVER['PHP_SELF'] gives only the house.php
(My page full url is house.php?p_id=10111
like this) Please help me to solve this problem. thanks.
在表单操作中,我想使用带有参数的页面名称。喜欢house.php?p_id=10111
。但是 $_SERVER['PHP_SELF'] 只给出了house.php
(我的页面完整网址是house.php?p_id=10111
这样的)请帮我解决这个问题。谢谢。
回答by Shef
How about leaving it empty, what is wrong with that?
让它空着怎么样,那有什么问题?
<form name="form1" id="mainForm" method="post" enctype="multipart/form-data" action="">
</form>
Also, you can omit the action attribute and it will work as expected.
此外,您可以省略 action 属性,它会按预期工作。
回答by shaggy
You can leave action blank or use this code:
您可以将操作留空或使用以下代码:
<form name="form1" id="mainForm" method="post" enctype="multipart/form-data" action="<?php echo $_SERVER['REQUEST_URI'];?>">
</form>
回答by Matt R. Wilson
Leaving the action value blank will cause the form to post back to itself.
将操作值留空将导致表单回传给自身。
回答by joskah
You can use an echo shortcut also instead of typing out "echo blah;" as shown below:
您也可以使用回声快捷方式而不是输入“echo blah;” 如下所示:
<form method="POST" action="<?=($_SERVER['PHP_SELF'])?>">
回答by Lakshman Kambam
This is Perfect. try this one :)
太棒了。试试这个:)
<form name="test" method="post" enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>">
/* Html Input Fields */
</form>
回答by Arda
回答by gleb
If you want to be secure use this:<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
如果你想安全使用这个:<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">