使用Firefox / IE丢失发布的数据,Safari可以使用

时间:2012-12-30 16:13:21

标签: html forms post

我正在调试一个php脚本,我已将其缩小为:

index.php:
<html>
<body>
<?php
$id = "42";
echo "<form action=\"handle_data.php\" method=\"post\">";
echo "<input type=\"image\" src=\"my_button.png\" name=\"id\" value=\"$id\">";
echo "</form>";
?>
</body>
</html>

_

handle_data.php:
<?php

echo 'PHP Input:<br />';
echo file_get_contents('php://input');
echo '<br />';
echo 'Post variables:<br />';
print_r($_POST);

?>

在Mac或iOS设备上使用Safari效果很好:

PHP Input:
id.x=108&id.y=83&id=42
Post variables:
Array ( [id_x] => 108 [id_y] => 83 [id] => 42 )

但是,使用Win7与IE8或Firefox 17,发布的数据'42'丢失= /

PHP Input:
id.x=128&id.y=96
Post variables:
Array ( [id_x] => 128 [id_y] => 96 )

为什么哦为什么?

1 个答案:

答案 0 :(得分:0)

根据this blog Firefox和IE遵循HTML5标准。它提供了CSS替代方案。

将您的input元素更改为:

<input type='submit' name='id' value='$id' class='mySubmit' />

并添加CSS:

input.mySubmit {
  border: none;
  cursor: pointer;
  display: inline-block;
  text-indent: -3000px;
  background: url(my_button.png) no-repeat 50% 50%;
  width: 50px;
  height: 20px;
}