[英]How do I pull data from a form into a session using an out of form input
我受到預先存在的約束的限制,需要保持該項目的結構相同。 我正在使用PHP生成表單並根據需要填充頁面。
我有一份客戶信息表
<form action="index.php" method="POST" id="cust-form">
<input type="text" name="cust-name"></input>
<input type="submit" value="submit" name="submit">
</input>
下面我有一個搜索表單
<form action="index.php" method="POST" id="form">
<input type="text" name="search-tags"></input>
<input type="submit" value="submit" name="Search">
</input>
並且可變數量的表單可以出現在頁面的其余部分,通常只是一個變量進程按鈕以傳遞給php后端。
我一直在遇到將客戶數據傳遞到帖子格式的問題,因此可以通過php后端進行處理。 我試過用javascript
var form = document.getElementById('form');
var data = $('#cust-form').serialize();
data.split('&');
var cust_name = document.createElement("input");
cust_name.setAttribute("type", "hidden");
cust_name.setAttribute("name", "cust-name");
cust_name.setAttribute("value", data[0]);
form.appendChild(cust_name);
但是這不會出現在我收到的POST請求中。 在不必對代碼結構進行大修的情況下,獲得該請求的最佳方法是什么?
您是否能夠將隱藏的“cust-name”輸入添加到html中,或者這是您無法修改的內容?
根據MDN( https://developer.mozilla.org/en-US/docs/Web/API/Element/setAttribute )使用setAttribute來設置值不一致。 你應該試試這個:
cust_name.value = data[0];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.