不能一起工作?在 HTML 中-6ren"> 不能一起工作?在 HTML 中-如果我只使用这段代码 但我希望 name="send"也可以同时工作(在 isset($_POST['send']) 中)。但它不起作用。所以我可以为这两种情况做吗? 我需要同时下载数据并将数据发送到-6ren">
gpt4 book ai didi

php - 和表单 不能一起工作?在 HTML 中

转载 作者:行者123 更新时间:2023-11-28 02:26:19 25 4
gpt4 key购买 nike

如果我只使用这段代码 <a href works >但我希望 name="send"也可以同时工作(在 isset($_POST['send']) 中)。但它不起作用。所以我可以为这两种情况做吗?

我需要同时下载数据并将数据发送到数据库。

<a href="./users/assets/upload/file/<?php echo $result['product_file']; ?>">
<form method="POST" action=" ">
<div class="row" style="background-color: #8CC63F;">
<div class="col-lg-12 dw_text text-center">
<button type="submit" name="send" style="font-size: 30px;">FREE DOWNLOAD</button>
</div>
</form>
</a>

最佳答案

在提交表单之前,您需要更正您的 HTML。看起来您在按下“免费下载”按钮时正在调用 url

要更正 HTML,您可以直接使用链接的 url 作为表单的 action(像这样)

  <form method="POST" action="./users/assets/upload/file/<?php echo $result['product_file']; ?>">
<div class="row" style="background-color: #8CC63F;">
<div class="col-lg-12 dw_text text-center">
<button type="submit" name="send" style="font-size: 30px;">FREE DOWNLOAD</button>
</div>
</form>

或使用 jQuery(正如您在评论中提到的那样)将表单提交到相同的 url。请参阅下面的示例,

$.ajax({
type: 'POST',
url: "./users/assets/upload/file/<?php echo $result['product_file']; ?>",
data: $(this).serialize(),
success: function(data) { }
});

为了保持上述ajax提交中的url整洁,可以将$result['product_file'];作为隐藏字段在 HTML 中。因此,当我们按下“免费下载”按钮时,$(this).serialize() 也会序列化该值。因此,该 url 看起来与此类似,

url: "./users/assets/upload/file",

在 PHP 后端,product_file 的检索需要稍微修改以适应这一新变化。

希望对你有帮助

谢谢

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com