10
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

IEの<input type="image" />対策

Posted at

input type="image" をクリックしたとき、IEではname属性を送らずに、画像の縦横のサイズを送ってくるので、PHPでname属性が来ることを期待するような作りになっているとハマる。

image_xやimage_yがあるかも込みでハンドルしてもいいけど、name属性を配列にしておくと、
type="submit"でもtype="image"でも同じキーが渡ってくるので楽。

<!-- フォーム1 -->
<form action="" method="post">

	<input type="submit" name="submit" value="送信" />
	<input type="image" name="image" value="画像" />
</form>

<!-- フォーム2 -->
<form action="" method="post">

	<input type="submit" name="submit[dummy]" value="送信" />
	<input type="image" name="image[dummy]" value="画像" />
</form>

<?php

var_dump($_POST);

// フォーム1

	// Chrome + submit
	// array(1) { ["submit"]=> string(6) "送信" }

	// Crhome + image
	// array(3) { ["image_x"]=> string(2) "16" ["image_y"]=> string(1) "4" ["image"]=> string(6) "画像" }

	// IE8 + image(ここでたいていハマる)
	//array(2) { ["image_x"]=> string(2) "12" ["image_y"]=> string(2) "25" }

// フォーム2

	// Chrome + submit, IE8 + submit
	// array(1) { ["submit"]=> array(1) { ["dummy"]=> string(6) "送信" } }

	// Chrome + image
	// array(1) { ["image"]=> array(1) { ["dummy"]=> string(6) "画像" } }

	// IE8 + image
	// array(1) { ["image"]=> array(1) { ["dummy"]=> string(2) "20" } }
10
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?