Wayne State Web Team

Wayne State University Web Team Blog

HTML button vs input submit tag

Internet Explorer 6 & 7 have a different approach in handling the button input submit tag.  In IE it posts the innerHTML of the button rather than what the value attribute is (like other browsers do).  This becomes an issue when checking the submit value to handle a form post.  See the following code: if($_POST['submit'] == 'Submit') { // Do Something }

<button type="submit" name="submit" value="Submit"><img src="tick.gif" height="16" width="16" alt="Tick" /> Submit</button>

Looks normal right? You would assume the post value would be equal to "Submit" after submitting the form. Well, in IE6 and IE7 the post value would actually be "Tick Submit".

How can we fix this?

By applying two functions to your conditional statement you can easily ensure that it will be the same so long as the text inside the value attribute and the text inside the HTML are equal. See the following code:

if(trim(strip_tags($_POST['submit'] ))== 'Submit') { // Do Something }

Strip tags will remove the img tag, and trim will ensure there will be no spaces around what is left. This will result in "Submit" = "Submit" which is exactly what we want.