首页 > <input type="image" name="save">提交后$_POST['save_x']

<input type="image" name="save">提交后$_POST['save_x']

<input type="image" name="save" src="some_image.gif" value="some_value">

点击上面的图片按钮提交后参数$_POST['save_x']和$_POST['save_y']中的值是什么含义,chrome中好像还有$_POST['save']=some_value的值,而ie和firefox中好像没有。


当提交表单时,可以用一张图片代替标准的提交按钮。

php<?php 
if(isset($_POST['action'])) {
    var_dump($_POST);
} else {
    $s = <<<STR
<form action="{$_SERVER['PHP_SELF']}" method="post">
<input type="hidden" name="action" value="1">
<input type="image" src="go.jpg" name="sub">
</form>
STR;
    echo $s;
}

对于上面这段程序,当用户点击图片某处时,表单会传送到服务器,并加上两个变量sub_xsub_y,包含了用户点击图片的坐标。

array (size=3)
  'action' => string '1' (length=1)
  'sub_x' => string '334' (length=3)
  'sub_y' => string '282' (length=3)

其实,POST的数据为sub.xsub.y,由于.在PHP中不是合法的标识符组成元素,故PHP将其转换为sub_xsub_y

参考:http://php.net/manual/zh/language.variables.external.php

【热门文章】
【热门文章】