可能重复:
same form data, different actions on two separate submit buttons
upload form within a contact form, the upload form submit keeps submitting the whole form
我在php联系表单中有一个文件上传部分,文件上传的提交按钮,而是提交表单。我如何区分两个提交按钮?
它基本上是两个POST表单,文件在php联系表单中上传。
答案 0 :(得分:3)
给每个人一个名字:
<input type="submit" name="submit1" value="Submit 1">
<input type="submit" name="submit2" value="Submit 2">
if (isset($_POST['submit1'])) {
// submit 1 pressed
}
else if (isset($_POST['submit2'])) {
// submit 1 pressed
}
答案 1 :(得分:2)
示例表单:
<form method="post">
<input type="submit" name="submit1" value="Button1">
<input type="submit" name="submit2" value="button2">
</form>
然后使用name=""
服务器端..
<?php
if (isset($_POST['submit1']))
{
echo "Button1 Is Set <br>";
}
if (isset($_POST['submit2']))
{
echo "Button2 Is Set <br>";
}
?>