![](/img/trans.png)
[英]Storing customisable quiz questions and answers in a .txt file using PHP
[英]Sending quiz answers using a php form
我有形式工作正常。 我有一個測驗工作正常。
當我合並兩個他們不能正常工作:(
測驗作為一個測驗,但它不會使用PHP發送到我的電子郵件地址。
這是我的一些代碼:
<head>
<script>
CorrectAnswers = new Array();
CorrectAnswers[0]=1;
CorrectAnswers[1]=1;
CorrectAnswers[2]=1;
CorrectAnswers[3]=2;
macrightchar='YES';
macwrongchar='NO';
winrightchar='YES';
winwrongchar='NO';
var platform = 'win'
if (navigator.appVersion.indexOf('Mac') != -1) {platform = 'mac'}
if (platform == 'mac') {
rightchar = unescape(macrightchar)
wrongchar = unescape(macwrongchar)
}
else {
rightchar = unescape(winrightchar)
wrongchar = unescape(winwrongchar)
}
function CheckAnswer(){
var i = 0;
var TotalCorrect = 0;
var x = 0;
var Score = 0;
for (i=0; i<CorrectAnswers.length; i++){
if (document.QuizForm.elements[i*2].selectedIndex == CorrectAnswers[i]){
document.QuizForm.elements[(i*2)+1].value = rightchar;
TotalCorrect++;
}
else{
document.QuizForm.elements[(i*2)+1].value = wrongchar;
}
}
Score = Math.floor((TotalCorrect*100)/CorrectAnswers.length);
document.CheckForm.ScoreBox.value = Score + '%';
}
</script>
</head>
<body>
<form name="QuizForm" accept-charset="utf-8" method="post" action="forms/quiz/_process.php" onSubmit="return validate.check(this)">
<table class="widthOneHundredPercent">
<tr>
<td class="tableCellFloat columnOne" valign="top">
<label for="Big_Media_offers_a_great_multiplatform_tool">Big Media offers a great multiplatform tool</label>
</td>
<td class="tableCellFloat columnTwo" valign="top">
<select name="0">
<option>???</option>
<option>True</option>
<option>False</option>
</select>
<td valign=top>
<input type="text" name="1" size=2 maxlength=2>
</td>
</td>
</tr>
<tr>
<FORM name="CheckForm">
<td align="center">
<font face="Geneva,Arial"><input type="button" VALUE="Check" onClick="CheckAnswer()"> Your score is <input type=text name="ScoreBox" size="4" maxlength="4"></font>
<center><input type="submit" value="Submit Form" /></center>
</form>
當按下提交時,它會將地址欄中我的文件名末尾從quiz.php更改為quiz.php?ScoreBox = 75%25。 所以它需要我正確的答案和錯誤的答案。
當點擊檢查分數時,我需要測驗顯示實時的正確和錯誤的答案,但我還需要使用PHP發送結果。
如果我完全錯了,或許有人可以指出我正確的方向重新開始。
問候。
在打開“CheckForm”之前,嘗試為“QuizForm”添加結束<form>
標記。
[編輯]實際上,QuizForm似乎沒有提交方法。
我在這里注意到的一些事情:
QuizForm
沒有提交按鈕,似乎沒有動態提交(可能沒有顯示)。 也許這種形式和CheckForm
可以結合起來。 CheckForm
沒有定義method
,這就是提交在其上放置查詢字符串的原因 答案可能就像將提交按鈕從CheckForm
移動到QuizForm
一樣簡單。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.