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.
Add name="submit" to your submit button. If you view source on the form in the browser, you'll see how it submits to self - the form's action attribute will contain the name of the current script - therefore when the form submits, it submits to itself.
PHP self-processing form. Sometimes, you want to include both form and logic for handling form submission in a single PHP file. This form is often referred to as a self-processing form. To create a self-processing form, you can use the $_SERVER['REQUEST_METHOD'] that returns the request method e.g., GET or POST .
<form name="bizLoginForm" method="post" action="?
The $_SERVER["PHP_SELF"] is a super global variable that returns the filename of the currently executing script. So, the $_SERVER["PHP_SELF"] sends the submitted form data to the page itself, instead of jumping to a different page. This way, the user will get error messages on the same page as the form.
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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With