HTML表单无法使用图片提交按钮?

时间:2013-02-02 23:53:26

标签: php html forms

我正在测试以下html表单。

<html>

<head>
<link href = "style.css" rel = "stylesheet" type = "text/css">
</head>

<form action = "test1.php" enctype = "multipart/form-data" method = "POST">
<input type = "hidden" name = "playno" value = "testing">
<input type = "image" src = "uploads/defb.png"  name = "submit" value = "submit"/>
</form>

</html>

以下内容保存在“test1.php”中:

<?php

$hiddenvalue = $_POST['playno'];

if (isset($_POST['submit'])){
echo "OK";
}
else
{
echo "error";
}

?>

在broswer中,当我打印$ hiddenvalue时,我返回值“testing”。但是,每次输出“错误”,而不是“确定”。

我非常感谢任何帮助。这让我发疯! 非常感谢提前。

3 个答案:

答案 0 :(得分:2)

使用input type="image"时,浏览器会发送submit_xsubmit_y

因此在PHP中,$_POST['submit']将无法使用,但会定义$_POST['submit_x']$_POST['submit_y'](包含点击图像的X / Y坐标)。

答案 1 :(得分:1)

只需在表单中添加:

<input type="hidden" name="submit" value="submit"/>

这样它就会在你的PHP中收到$_POST['submit']

答案 2 :(得分:-1)

<input type = "image" src = "uploads/defb.png"  name = "submit" value = "submit"/>

更改为:

<input type = "submit"  name = "submit" value = "submit"/>

因为输入没有这种类型

创建输入样式 HTML

<input type = "submit"  name = "submit" value = "submit" id="button" />

CSS

#button {

background:url("uploads/defb.png");
border:0;
outline:0;

}