繁体   English   中英

html、js 和 php,以表单形式发送单选按钮

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM