[英]html, js and php, sending radio button in form
我在向此表單添加單選按鈕時遇到問題。 我沒有將單選按鈕數據發送到電子郵件的代碼。 我正在使用這些文件: https://github.com/myprogrammingblog/myprogrammingblog.com/tree/master/UI%20Components/contact%20form然后將以下內容添加到 html 文件中:
<input type="radio" name="pipelineType" value="3d" checked id="3d" onclick="displayType('3d')">Yes </td>
<input type="radio" name="pipelineType" value="3d" id="3d" onclick="displayType('3d')"> No </td>
我嘗試調整 js 和 php 文件,但它使表單完全不起作用。 有任何想法嗎?
-謝謝
編輯:嘗試運行它時給出這個:GET http://www.yourdomain.com/js/contact_me.js [HTTP/1.1 304 Not Modified 274ms] 21:00:23.196 SyntaxError:標識符在數字文字contact_me之后立即開始。 js:20 21:00:23.204 不推薦使用 getPreventDefault()。 請改用 defaultPrevented。
我認為你需要更正你的 html 輸入字段,像下面的代碼一樣正確地結束它們:
<td>
<input type="radio" name="pipelineType" value="3d" checked id="3d" onclick="displayType('3d')" />Yes
</td>
您有一個具有相同值的單選按鈕字段,因此請刪除一個。
在 HTML 中(文件 form.html)
<form name="sentMessage" class="well" id="contactForm" novalidate>
<input type="radio" name="pipelineType" value="3d" checked id="3d" onclick="displayType('3d')">Yes </td>
<input type="radio" name="pipelineType" value="no_3d" id="no_3d" onclick="displayType('no_3d')"> No </td>
...
</form>
在聯系表格/js/contact_me.js
$(function() {
$("input,textarea").jqBootstrapValidation(
{
submitSuccess: function ($form, event) {
//..your code
//todo: adding pipelineType to data and submit to server
let pipelineType = document.querySelector('[name="pipelineType"]:checked').value
$.ajax({
url: "./bin/contact_me.php",
type: "POST",
data: {name: name, email: email, message: message, pipelineType: pipelineType},
///....
});
}
})
});
在聯系表格/bin/contact_me.php
<?php
//
$name = $_POST['pipelineType'];//value will be 3d or no_3d
//...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.