Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Forms with action=""

Tags:

html

forms

I just found out (the hard way), that when you have a HTML form with action="", Webkit browsers treat it differently to Firefox and Internet Explorer.

In FF and IE, these two form tags are equivalent:

<form method="post" action="">  <form method="post"> 

They will both submit the form back to the same page. Safari and Chrome however will send that first form to the default page (index.php, or whatever) - the second form works the same as FF/IE.

I've quickly hacked my code so that anywhere where it would normally print an empty action, it doesn't add an action attribute at all.

This seems very messy and not the best way to be doing things. Can anyone suggest a better method? Also, can anyone enlighten me about why Webkit would do such a thing?

like image 301
nickf Avatar asked Jan 06 '09 02:01

nickf


People also ask

What is action in a form?

The action attribute defines the action to be performed when the form is submitted. Usually, the form data is sent to a file on the server when the user clicks on the submit button. In the example below, the form data is sent to a file called "action_page.php".

What is form action method?

The method attribute specifies how to send form-data (the form-data is sent to the page specified in the action attribute). The form-data can be sent as URL variables (with method="get" ) or as HTTP post transaction (with method="post" ). Notes on GET: Appends form-data into the URL in name/value pairs.

Does a form require an action?

Yes, the form is required to have an action attribute in HTML4.

What is action property form?

The Form action property in HTML DOM is used to set or return the value of the action attribute of the Form. After submission of form the action attribute called. The form data is to be sent to the server after submission of form. Syntax: It is used to return the action property.


1 Answers

I usually use

<form method='POST' action='?'> 

This means the current URL but with no parameters.

like image 85
staticsan Avatar answered Sep 29 '22 06:09

staticsan