HTML表单不能与图像加工提交按钮?(HTML form not working with imag

2019-08-16 17:21发布

我有以下的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。 然而每一次输出“错误”为好,而不是“OK”。

我将不胜感激任何帮助。 这是推动我疯了! 提前谢谢了。

Answer 1:

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

所以在PHP中, $_POST['submit']将无法使用,但$_POST['submit_x']$_POST['submit_y']将被定义(含X / Y坐标被点击图像的位置)。



Answer 2:

就在表单中添加此:

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

因此,它收到$_POST['submit']在你的PHP。



Answer 3:

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

改成:

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

由于输入didint有这种类型

创建输入HTML样式

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

CSS

#button {

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

}


文章来源: HTML form not working with image submit button?
标签: php html forms