对于练习,我需要制作一个允许人们申请网球锦标赛的PHP表格。它需要有一个地方填写你的名字,姓氏,网球俱乐部,你的技能水平(范围1-7),你想要的类别(也是1-7),你的电子邮件地址和申请人可能有的潜在评论。
构建表单不是问题,而是制作第一个版本。但是,要求已经发生变化,现在我们需要确保申请人的技能水平不能比他们正在玩的所需类别更低,因为这些技能直接与技能相关联。允许玩高于你级别的类别。为了更清楚地说明,我有一个例子。
此要求的限制,例1:
示例2:
示例3:
如前所述,第一个版本已经完成,但我不确定如何将这些新需求合并到文件中。代码可以在下面找到:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Application form</title>
</head>
<body>
<h3>
<form id="form1" name="form1" method="post">
Welcome to this application form for our tennis tournament. In order to succesfully apply yourself for this tournament we want to know the following information about you as an athlete; your first name, your seconde name, your club, your licence number, category, email adresses and extra information if deemed of use by you. Good luck and we look forward to seeing you at the tournament.
</form>
</h3>
<label for="textfield2">First name:</label>
<input type="text" name="textfield2" id="textfield2">
<label for="textfield3"><br>
Last name:</label>
<input type="text" name="textfield3" id="textfield3">
<label for="textfield4"><br>
Extra (optional):</label>
<input type="text" name="textfield" id="textfield">
<label for="textfield4"><br>
Club:</label>
<input type="text" name="textfield4" id="textfield4">
<h1>Your license number, this is needed to ensure that your results are valid.</h1>
<table width="200">
<tr>
<td><label>
<input type="radio" name="RadioGroup1" value="1" id="RadioGroup1_3">
License number 1</label></td>
</tr>
<tr>
<td><label>
<input type="radio" name="RadioGroup1" value="2" id="RadioGroup1_4">
License number 2</label></td>
</tr>
<tr>
<td><label>
<input type="radio" name="RadioGroup1" value="3" id="RadioGroup1_5">
License number 3</label></td>
</tr>
<tr>
<td><label>
<input type="radio" name="RadioGroup1" value="4 " id="RadioGroup1_6">
License number 4</label></td>
</tr>
<tr>
<td><label>
<input type="radio" name="RadioGroup1" value="5" id="RadioGroup1_7">
License number 5</label></td>
</tr>
<tr>
<td><label>
<input type="radio" name="RadioGroup1" value="6" id="RadioGroup1_8">
License number 6<br>
</label></td>
</tr>
<tr>
<td><label>
<input type="radio" name="RadioGroup1" value="7" id="RadioGroup1_9">
License number 7</label></td>
</tr>
</table>
<h1>Your category, arranged by skill.</h1>
<table width="200">
<tr>
<td><label>
<input type="radio" name="Categorie" value="7" id="Categorie_0">
Not skilled - 7<br>
</label></td>
</tr>
<tr>
<td><label>
<input type="radio" name="Categorie" value="6" id="Categorie_1">
Less skilled - 6</label></td>
</tr>
<tr>
<td><label>
<input type="radio" name="Categorie" value="5" id="Categorie_2">
Unskilled - 5</label></td>
</tr>
<tr>
<td><label>
<input type="radio" name="Categorie" value="4" id="Categorie_3">
Average - 4</label></td>
</tr>
<tr>
<td><label>
<input type="radio" name="Categorie" value="3" id="Categorie_4">
Skilled - 3</label></td>
</tr>
<tr>
<td><label>
<input type="radio" name="Categorie" value="2" id="Categorie_5">
Good - 2</label></td>
</tr>
<tr>
<td><label>
<input type="radio" name="Categorie" value="1" id="Categorie_6">
Genius - 1</label>
<label for="email"><br>
Your email adress:</label> <input type="email" name="email" id="email"></td>
</tr>
</table>
<label for="textarea">Comments and extra information:</label>
<textarea name="textarea" id="textarea"></textarea>
<input type="submit" name="submit" id="submit" value="Send">
<table width="200">
<tr> </tr>
</table>
</body>
</html>
如果您对上述信息有任何疑问,请随时提出。欢迎所有提示,包括上述问题和一般编码。
提前致谢!
答案 0 :(得分:0)
您可以在数据库中创建技能与类别的表...或者在您的javascript中保存数组(如果这种Category.num和Category.requiredSkillLevel对的数量较少并且是固定的)客户端验证...现在,如果用户输入他的技能水平和他想要的类别,您可以轻松测试
if(UserInput.category == Category.num){
if(UserInput.skills < Category.requiredSkillLevel){
alert("Participant is not eligible to participate in this category.");
}
else{
alert("Participant is eligible");
}
function validateForm(){
var skill = $("input[type='radio'][name='RadioGroup1']:checked").val();
var cat = $("input[type='radio'][name='Categorie']:checked").val();
if(skill<cat){
alert("Not Eligible");
return false;
}
else{
alert("Eligible!");
return true;
}
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h3>
Welcome to this application form for our tennis tournament. In order to succesfully apply yourself for this tournament we want to know the following information about you as an athlete; your first name, your seconde name, your club, your licence number, category, email adresses and extra information if deemed of use by you. Good luck and we look forward to seeing you at the tournament.
</h3>
<form id="form1" name="form1" method="post" onsubmit="return validateForm()">
<label for="textfield2">First name:</label>
<input type="text" name="textfield2" id="textfield2">
<label for="textfield3"><br>
Last name:</label>
<input type="text" name="textfield3" id="textfield3">
<label for="textfield4"><br>
Extra (optional):</label>
<input type="text" name="textfield" id="textfield">
<label for="textfield4"><br>
Club:</label>
<input type="text" name="textfield4" id="textfield4">
<h1>Your license number, this is needed to ensure that your results are valid.</h1>
<table width="200">
<tr>
<td><label>
<input type="radio" name="RadioGroup1" value="1" id="RadioGroup1_3">
License number 1</label></td>
</tr>
<tr>
<td><label>
<input type="radio" name="RadioGroup1" value="2" id="RadioGroup1_4">
License number 2</label></td>
</tr>
<tr>
<td><label>
<input type="radio" name="RadioGroup1" value="3" id="RadioGroup1_5">
License number 3</label></td>
</tr>
<tr>
<td><label>
<input type="radio" name="RadioGroup1" value="4 " id="RadioGroup1_6">
License number 4</label></td>
</tr>
<tr>
<td><label>
<input type="radio" name="RadioGroup1" value="5" id="RadioGroup1_7">
License number 5</label></td>
</tr>
<tr>
<td><label>
<input type="radio" name="RadioGroup1" value="6" id="RadioGroup1_8">
License number 6<br>
</label></td>
</tr>
<tr>
<td><label>
<input type="radio" name="RadioGroup1" value="7" id="RadioGroup1_9">
License number 7</label></td>
</tr>
</table>
<h1>Your category, arranged by skill.</h1>
<table width="200">
<tr>
<td><label>
<input type="radio" name="Categorie" value="7" id="Categorie_0">
Not skilled - 7<br>
</label></td>
</tr>
<tr>
<td><label>
<input type="radio" name="Categorie" value="6" id="Categorie_1">
Less skilled - 6</label></td>
</tr>
<tr>
<td><label>
<input type="radio" name="Categorie" value="5" id="Categorie_2">
Unskilled - 5</label></td>
</tr>
<tr>
<td><label>
<input type="radio" name="Categorie" value="4" id="Categorie_3">
Average - 4</label></td>
</tr>
<tr>
<td><label>
<input type="radio" name="Categorie" value="3" id="Categorie_4">
Skilled - 3</label></td>
</tr>
<tr>
<td><label>
<input type="radio" name="Categorie" value="2" id="Categorie_5">
Good - 2</label></td>
</tr>
<tr>
<td><label>
<input type="radio" name="Categorie" value="1" id="Categorie_6">
Genius - 1</label>
<label for="email"><br>
Your email adress:</label> <input type="email" name="email" id="email"></td>
</tr>
</table>
<label for="textarea">Comments and extra information:</label>
<textarea name="textarea" id="textarea"></textarea>
<input type="submit" name="submit" id="submit" value="Send">
<table width="200">
<tr> </tr>
</table>
</form>
&#13;
你走了......如果我误解了你的问题,请纠正我。