[英]form with multiple questions and answers
I want to store question with multiple choice answers. 我想将问题与多个选择答案一起存储。 The amount of answers can differ from 2 to more answers.
答案数量可以从2个到更多答案不等。
I have a few questions for this. 我对此有几个问题。 But first I will show my current code:
但是首先我将显示当前代码:
html: 的HTML:
<div class="questionFormTemplate">
<form action="utils/handleForm.php" method="post">
<table>
<tr>
<td><input type="text" name="question" value="question?"/></td>
</tr>
<tr>
<td><input type="text" name="answer[]" value="answer 1"/></td>
<td><input type="button" value="remove" class="remove"/></td>
</tr>
<tr>
<td><input type="text" name="answer[]" value="answer 2"/></td>
<td><input type="button" value="remove" class="remove"/></td>
</tr>
<tr>
<td><input type="button" value="add answer"/></td>
</tr>
</table>
<input type="submit" value="update" />
</form>
</div>
<div id="container"></div>
js / jquery: js / jquery:
// add some question forms to the container
var questionFormTemplate = $('.questionFormTemplate').html();
console.log(questionFormTemplate);
for(var i = 0; i < 8; i++) {
$('.container').append(questionFormTemplate);
}
// make the buttons work
$('input[type="button"][value="remove"]').on("click", function() {
$(this).parent().parent().remove();
});
$('input[type="button"][value="add answer"]').on("click", function() {
$(this).parent().parent().parent().append('<tr><td><input type="text" name="answer[]" value="answer"/></td><td><input type="button" value="remove" class="remove"/></td></tr>');
});
css: CSS:
.questionFormTemplate {
display: none;
}
http://jsfiddle.net/clankill3r/5nkunpsw/3/ http://jsfiddle.net/clankill3r/5nkunpsw/3/
1) Is it easier to make a form for every question, or one form with all questions? 1)为每个问题或为所有问题形成一个表格是否更容易?
2) How can I know which question is sended to handleForm.php (as in 1, 2 or 3 etc.) 2)我怎么知道哪个问题发送到handleForm.php(如1、2或3等)
3) Is my current approach good or bad?, I need to be able to display what's in the database as well. 3)我当前的方法是好是坏?,我还需要能够显示数据库中的内容。
Well one thing I would suggest is giving each problem an id attribute which you can then send to your php class which can validate from the database. 好吧,我建议给每个问题一个id属性,然后将其发送到可以从数据库进行验证的php类。 For example for form 1 question 2 you could give it "id=12".
例如,对于表格1问题2,您可以给它“ id = 12”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.