HTML form not working with image submit button?

2020-05-03 18:58发布

I have the following html form i am testing out.

<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>

The following is saved in "test1.php":

<?php

$hiddenvalue = $_POST['playno'];

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

?>

In the broswer i am returned the value "testing" when i print $hiddenvalue. However each and every time it outputs "error" as well, not "OK".

I would greatly appreciate any help. It is driving me mad!!! Many thanks in advance.

标签: php html forms
3条回答
Bombasti
2楼-- · 2020-05-03 19:08

Just add this inside the form:

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

So that it receives the $_POST['submit'] in your PHP.

查看更多
姐就是有狂的资本
3楼-- · 2020-05-03 19:12

When using a input type="image", the browser sends submit_x and submit_y.

So in PHP, $_POST['submit'] will not be available, but $_POST['submit_x'] and $_POST['submit_y'] will be defined (containing the X/Y coordinates where the image was clicked on).

查看更多
我只想做你的唯一
4楼-- · 2020-05-03 19:20
<input type = "image" src = "uploads/defb.png"  name = "submit" value = "submit"/>

change to:

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

Because input didint have this type

create style for input HTML

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

CSS

#button {

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

}
查看更多
登录 后发表回答