Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using <button type="submit"> as replacement of <input type="submit"> to submit forms, problems?

Tags:

html

forms

<button> tags are more easily stylable than inputs, and I'm really in favor of using them. However I'm afraid some problems may arise.

From W3schools: Note: If you use the <button> element in an HTML form, different browsers may submit different values. Use <input> to create buttons in an HTML form.

I also read that IE has problems with this buttons. I'm only looking to use them as a replace for submit buttons, eg:

<form>
<input type="text" name="post"/>
<button type="submit">
</form>

Will they work the same as submit buttons or will I have problems like unsupported browsers or anything else?

like image 572
lisovaccaro Avatar asked Oct 05 '22 21:10

lisovaccaro


2 Answers

The button element has had serious problems with IE, which used to have a very broken implementation. This still remains a concern. According to MDN page on button, IE 7 is still very broken in this respect, sending wrong data upon submission.

But if your form handling does not depend on the name=value data that results from a button element, button type=submit is safe these days. For example, when you have only one such button in the form, you probably wouldn’t use the name=value pair for anything anyway.

like image 73
Jukka K. Korpela Avatar answered Oct 10 '22 04:10

Jukka K. Korpela


I haven't experienced any IE problems with a <button type="submit">, and at the very very worse, you can always attach an onclick event handler to it.

A <button> should be safe to use.

As a final note: w3schools is a wrong and misleading site. You shouldn't use it as reference for any sort of language. For PHP, there's the PHP Manual, for JavaScript, there's Mozilla Developer Network (or MDN). See http://w3fools.com to further understand why you should never use w3schools.

like image 45
Madara's Ghost Avatar answered Oct 10 '22 03:10

Madara's Ghost