我想学习php/html.因此,我做了一个简单的代码,如下所示:

form.php

<form autocomplete="off" action="form_result.php" enctype="multipart/form-data" method="POST">
    Company Name:<br>
    <input type="text" name="company" required><br>
    <input type="file" name="files[]" multiple class="my-image-field"><br><br>
    <input id="test" name="upload" type="submit" value="Upload" /></p>
</form>

form_result.php

<?php
if(isset($_POST['upload'])){
    echo "isset $ POST upload = true";
}
else{
    echo "isset $ POST upload = false";
}
?>

Above code give the expected result as the page show "isset $ POST upload = true" in the result_form.php
enter image description here

Based from one of the answer in this link and this link, I modify the code in form.php个 like this :

<form autocomplete="off" action="form_result.php" enctype="multipart/form-data" method="POST" 
onsubmit="document.getElementById('test').disabled = true">
    Company Name:<br>
    <input type="text" name="company" required><br>
    <input type="file" name="files[]" multiple class="my-image-field"><br><br>
<input id="test" name="upload" type="submit" value="Upload" /></p>
</form>

我预计它只是灰显的"Upload"按钮,Form_Result.php将显示与之前相同的结果,即"isset $ POST upload = true".但结果页面显示"isset $ POST upload = false"

enter image description here

所以,虽然"Upload"按钮灰显,但因为我预计结果页面显示"isset $ POST upload = true",所以我在这里错过了什么?

如有任何回应,我们将不胜感激.
提前谢谢你了.

推荐答案

因为disabled输入aren't submitted to the server.因此,submit按钮不包括在表单发布中.

不过,在处理表单服务器端时,只需判断任何其他输入即可实现相同的逻辑.例如:

if (isset($_POST['company'])) {
  echo "isset $ POST company = true";
} else {
  echo "isset $ POST company = false";
}

Php相关问答推荐

在保留唯一键值对的情况下高效合并嵌套数组

累加平面数组中数字子集的所有组合,以生成组合及其乘积的二维数组

PHP原始数据读取引发max_input_vars错误

用于计算付款费用的WooCommerce管理编辑产品中的自定义复选框

来自POST请求的(无效)json字符串中的奇怪字符(编码问题)

在laravel 9或10 php中向中间件响应添加自定义数据

FlySystem v3:使用本地适配器时出现问题

PHP-准备用于TCP套接字的数据包

使用HPOS过滤WooCommerce中的订单列表

Laravel Http::get not working on controller

如何使用 PHP 创建简化的 twig 替换?

如何将不同的 Woocommerce 费用合并为一个名称?

将一个表中的行连接为不同表MYSQL中的一列

PHP:数组的等边

将 WooCommerce 0 销售价格替换为自定义文本,并保留常规价格删除线

使用 PHP 的 OAuth 2.0 MAC

使用php删除数组中相同数字的所有变体

Docker: unixodbc.h 没有这样的文件或目录.已安装 unixodbc-dev 时出现pecl install sqlsrv错误

我应该清理 WP 查询中的 $_POST 吗?

将短代码添加到 woocommerce 产品页面