简体   繁体   English

如何发布选中的单选按钮

[英]How to post checked radio buttons

i have a jsfiddle here .这里有一个 jsfiddle。 What it does is that when the user clicks on the "Add Question" button, it adds a radio buttons in each row.它所做的是,当用户点击“添加问题”按钮时,它会在每一行中添加一个单选按钮。 But what I want to do is use $_POST to post selected radio buttons in each row into the the insertQuestions.php page (action the form takes use to).但我想做的是使用 $_POST 将每行中选定的单选按钮发布到 insertQuestions.php 页面(表单使用的操作)。

So what I want to know is how do I write the $_POST statement to be able to paste checked radio buttons?所以我想知道的是如何编写 $_POST 语句才能粘贴选中的单选按钮?

UPDATE:更新:

Is this code below correct in terms of finding the ReplyId for the selected radio by using z case statement then a query:下面这段代码在使用 z case 语句然后查询查找所选无线电的 ReplyId 方面是否正确:

$i = 0;
$c = count($_POST['reply']);

$insertquestion = array();

for($i = 0;  $i < $c; $i++ ){

    switch ($_POST['reply'][$i]){

    case "Single": 
    $selected_option = "Single";
    break;

    case "Multiple": 
    $selected_option = "Multiple";
    break;

    default:
    $selected_option = "";
    break;

    }      


    $replyquery = "SELECT ReplyId FROM Reply WHERE (ReplyType = '". mysql_real_escape_string($_POST['reply'])."')";
    $replyrs = mysql_query($replyquery);
    $replyrecord = mysql_fetch_array($replyrs);
    $replyid = $replyrecord['ReplyId']; 

All you need to do is when you run your AJAX script.您需要做的就是运行 AJAX 脚本。 On the process page you would use something like在流程页面上,您可以使用类似

<?PHP
$reply1 = $_POST['reply1'];
$reply2 = $_POST['reply2'];

however you will want to change the name of the input fields to name="reply[]" which will make the posted data an array 但是您需要将输入字段的名称更改为 name="reply[]"这将使发布的数据成为一个数组

UPDATE: The previous is only valid for checkboxes in this case (which there are none) With checkboxes of the same name, is checkbox 1 is checked and then checkbox 2 is checked, you will only get the value of checkbox 2 on the post.更新:在这种情况下,前一个仅对复选框有效(没有复选框)对于同名复选框,选中复选框 1,然后选中复选框 2,您将只能在帖子中获得复选框 2 的值。

Since reply is the name with a number after for duplicated questions, you can always get all posted variables by just using $_POST .由于 reply 是重复问题后带有数字的名称,因此您始终可以仅使用$_POST获取所有已发布的变量。 Doing this will give you an array of ALL posted data这样做会给你一个包含所有发布数据的数组

If you want to go through each reply since it is dynamic just do a foreach statement如果您想通过每个回复 go 因为它是动态的,只需执行一个 foreach 语句

foreach($_POST as $k=>$v) {
    //Run script to process each posted reply 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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