通过表单发送多个按钮信息

时间:2016-08-30 23:04:39

标签: php jquery html forms

我有一个包含多个按钮和值的表单。当我按下提交按钮和值时,我想提交单击了哪个按钮。我在下面的代码中使用php循环中的问题。代码显示是和每个问题没有按钮。我正在使用jquery来保持类的活动并切换它们(这很好)。我的问题是,当我提交表单时,只有问题是通过POST提交的,并且没有按下按钮的数据。如何处理此按钮以提交按钮(所有按钮都有唯一的ID)?

echo' <button type="button" name="yes'.$value[Key].'" id="answerf1" class="lietruth yes" >Yes</button>

 <button type="button" name="no'.$value[Key].'" id="answer1" class="lietruth no" >No</button>

<div id="questions">'.$value[Question].'</div>';
//submit button is after the loop

生成页面的HTML

<div id="Answertoggle16">
<div id="questions-box"><input type="hidden" name="question16" value="Question1"><input type="hidden" name="key"  value="5"><input type="hidden" name="user"  value="truthsandlie"><button type="button" name="yes5" id="answerf1" class="lietruth yes" >Yes</button><button type="button" name="no5" id="answer1" class="lietruth no" >No</button>
<div id="questions">Question1</div>
</div>
</div>
<div id="Answertoggle17">
<div id="questions-box"><input type="hidden" name="question17" value="Question2"><input type="hidden" name="key"  value="9"><input type="hidden" name="user"  value="truthsandlie"><button type="button" name="yes9" id="answerf1" class="lietruth yes" >Yes</button><button type="button" name="no9" id="answer1" class="lietruth no" >No</button>
<div id="questions">Question2</div>
</div>
</div>
<div id="Answertoggle18">
<div id="questions-box"><input type="hidden" name="question18" value="Question3"><input type="hidden" name="key"  value="25"><input type="hidden" name="user"  value="truthsandlie"><button type="button" name="yes25" id="answerf1" class="lietruth yes" >Yes</button><button type="button" name="no25" id="answer1" class="lietruth no" >No</button>
<div id="questions">Question3</div>
</div>
</div>
<div id="Answertoggle19">
<div id="questions-box"><input type="hidden" name="question19" value="Question4"><input type="hidden" name="key"  value="30"><input type="hidden" name="user"  value="truthsandlie"><button type="button" name="yes30" id="answerf1" class="lietruth yes" >Yes</button><button type="button" name="no30" id="answer1" class="lietruth no" >No</button>
<div id="questions">Question4</div>
</div>
</div>
<div id="Submit-answer" display: inline-block;"><button type="submit">Next</button>
</div>

2 个答案:

答案 0 :(得分:0)

使用log.addMessage({ message: '<span style="color: red;">[ERROR]</span>&nbsp;', isNewLine: false }); log.addMessage({ message: 'the rest of the error message', isNewLine: true }); 您可以设置提交按钮,如下所示:

type="submit"

然后你可以用<button type="submit" name="id1" value="value">Submit1</button> <button type="submit" name="id2" value="value">Submit2</button>... 来抓住它。

答案 1 :(得分:0)

这就是我所做的。添加了一个隐藏的div并使用javascript函数changeValue1(val)和changeValue2(val)更改该值。

$scope.$watch("arr",function (newVal,oldVal){
    console.log("value has changed from "+oldVal+" to "+newVal);
},true);