簡體   English   中英

在提交表單之前,將GET信息添加到POST請求中

[英]Adding the GET information to POST request before submitting the form

我有一個單擊特定日期的日歷,然后將它作為GET發送到表單文件,因此我在url上有一個表單:例如www.mydomain / form.php?date = 2017-11-12 。 當用戶提交表單時,我還需要將日期和表單字段一起發送。

如何將GET上的日期添加到POST請求中?

編輯:一些代碼:

在calendar.php上,無論何時我都有以下請求,請單擊:

window.open("http://mydomain/form.php?date=" + currentDate);

現在在form.php上,URL顯示:

 http://mydomain/form.php?date=20170430

(這只是一種簡單的形式(我正在測試中):)

<form action="send.php">
  First name:<br>
  <input type="text" name="firstname">
  <br>
  Last name:<br>
  <input type="text" name="lastname">
  <br>
  <input type="submit" value="Submit">
</form> 

所以我需要通過POST請求發送名字,姓氏和日期

使用hidden輸入

<input type="hidden" name="date" value="<?= $_GET['date']; ?>">

您可以在提交按鈕上綁定功能

$('[type="submit"]').on('click', function(e) {
    e.preventDefault();

    $('form[action="send.php"]').prop('action', 'http://mydomain/form.php?date=' + currentDate);
    $('form[action="send.php"]').submit();
});

提交數據前將更改表單的action屬性;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM