Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php form action php self

Tags:

forms

php

action

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.

like image 809
Sasindu H Avatar asked Jul 28 '11 16:07

Sasindu H


People also ask

How can create form submit itself in PHP?

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.

What is self processing form in PHP?

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 .

How do you make a form submit to itself?

<form name="bizLoginForm" method="post" action="?

What is the purpose of $_ PHP_SELF in PHP?

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.


2 Answers

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.

like image 144
Shef Avatar answered Sep 22 '22 05:09

Shef


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> 
like image 27
shaggy Avatar answered Sep 23 '22 05:09

shaggy