php form action php self

2019-01-17 11:09发布

I have a php form like this.

<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.

标签: php forms action
6条回答
可以哭但决不认输i
2楼-- · 2019-01-17 11:19

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>  
查看更多
霸刀☆藐视天下
3楼-- · 2019-01-17 11:24

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.

查看更多
Emotional °昔
4楼-- · 2019-01-17 11:39

You can use an echo shortcut also instead of typing out "echo blah;" as shown below:

<form method="POST" action="<?=($_SERVER['PHP_SELF'])?>">
查看更多
不美不萌又怎样
5楼-- · 2019-01-17 11:43

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>
查看更多
再贱就再见
6楼-- · 2019-01-17 11:43

Another (and in my opinion proper) method is use the __FILE__ constant if you don't like to rely on $_SERVER variables.

$parts = explode(DIRECTORY_SEPARATOR, __FILE__);
$fileName = end($parts);
echo $fileName;

About magic and predefined constants: 1, 2.

查看更多
做自己的国王
7楼-- · 2019-01-17 11:44

Leaving the action value blank will cause the form to post back to itself.

查看更多
登录 后发表回答