if /else in een form
Als ze op verzenden klikken moet er dit gebeuren:
tot 5 maal ja geslecteerd: antwoord 1
6 tot 8 maal ja: antwoord 2
9 tot 10 maal ja: antwoord 3
Wie kan mij helpen?
Anyway wat heb je tot nu toe?
Wat heb je al? En wat wil je precies dat wij doen?
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$aantal = count($_POST['antwoord']);
if ($aantal < 6) {
// ...
}
elseif ($aantal >= 6 && $aantal < 9) {
// ...
}
else {
// ...
}
}
?>
<form action="" method="post">
<input type="checkbox" name="antwoord[]"> 1
<input type="checkbox" name="antwoord[]"> 2
<input type="checkbox" name="antwoord[]"> 3
...
<input type="submit" value="GO">
</form>
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$aantal = count($_POST['antwoord']);
if ($aantal < 6) {
// ...
}
elseif ($aantal >= 6 && $aantal < 9) {
// ...
}
else {
// ...
}
}
?>
<form action="" method="post">
<input type="checkbox" name="antwoord[]"> 1
<input type="checkbox" name="antwoord[]"> 2
<input type="checkbox" name="antwoord[]"> 3
...
<input type="submit" value="GO">
</form>
Ik heb dit niet getest
Gewijzigd op 25/09/2012 17:15:37 door Kris Peeters
Code (php)
<form id="form1" name="form1" method="post" action="">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>ja</td>
<td> </td>
<td>nee</td>
</tr>
<tr>
<td><input type="radio" name="ja" id="ja" value="1" /></td>
<td> </td>
<td><input type="radio" name="nee" id="ja" value="1" /></td>
</tr>
<tr>
<td><input type="radio" name="ja" id="ja2" value="2" /></td>
<td> </td>
<td><input type="radio" name="nee" id="nee2" value="2" /></td>
</tr>
<tr>
<td><input type="radio" name="ja" id="ja3" value="3" /></td>
<td> </td>
<td><input type="radio" name="nee" id="nee3" value="3" /></td>
</tr>
<tr>
<td><input type="radio" name="ja" id="ja4" value="4" /></td>
<td> </td>
<td><input type="radio" name="nee" id="nee4" value="4" /></td>
</tr>
<tr>
<td><input type="radio" name="ja" id="ja5" value="5" /></td>
<td> </td>
<td><input type="radio" name="nee" id="nee5" value="5" /></td>
</tr>
<tr>
<td><input type="radio" name="ja" id="ja6" value="6" /></td>
<td> </td>
<td><input type="radio" name="nee" id="nee6" value="6" /></td>
</tr>
<tr>
<td><input type="radio" name="ja" id="ja7" value="7" /></td>
<td> </td>
<td><input type="radio" name="nee" id="nee7" value="7" /></td>
</tr>
<tr>
<td><input type="radio" name="ja" id="ja8" value="8" /></td>
<td> </td>
<td><input type="radio" name="nee" id="nee8" value="8" /></td>
</tr>
<tr>
<td><input type="radio" name="ja" id="ja9" value="9" /></td>
<td> </td>
<td><input type="radio" name="nee" id="nee9" value="9" /></td>
</tr>
<tr>
<td><input type="radio" name="ja" id="ja10" value="10" /></td>
<td> </td>
<td><input type="radio" name="nee" id="nee10" value="10" /></td>
</tr>
</table>
<input type="submit" name="verzend" id="verzend" value="Verzenden" />
</form>
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
echo '<form method="POST" action="">';
//Maak de opties aan
$i = 1;
while($i<=10){
echo 'Ja <input type="radio" name="'.$i.'" id="ja'.$i.'" value="ja" /> - Nee <input type="radio" name="'.$i.'" id="nee'.$i.'" value="nee" /> <br />';
$i++;
}
echo '<input type="submit"/></form>';
//check of de form is verstuurd
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$nee = 0;
$ja = 0;
//tel de opties op
$t = 1;
while($t<=10){
if($_POST[$t] == 'nee'){
$nee = $nee + 1;
}
if($_POST[$t] == 'ja'){
$ja = $ja + 1;
}
$t++;
}
//kijken hoeveel ja's er zijn gegeven
if($ja < 5){
echo 'minder dan 5<br/>Aantal ja:'.$ja.'<br/>Aantal nee:'.$nee;
}elseif($ja > 5 && $ja < 8){
echo 'tussen 5 en 9<br/>Aantal ja:'.$ja.'<br/>Aantal nee:'.$nee;
}elseif($ja > 8 && $ja < 11){
echo 'tussen 9 en 10<br/>Aantal ja:'.$ja.'<br/>Aantal nee:'.$nee;
}else{
echo 'Aantal ja:'.$ja.'<br/>Aantal nee:'.$nee;
}
}
?>
echo '<form method="POST" action="">';
//Maak de opties aan
$i = 1;
while($i<=10){
echo 'Ja <input type="radio" name="'.$i.'" id="ja'.$i.'" value="ja" /> - Nee <input type="radio" name="'.$i.'" id="nee'.$i.'" value="nee" /> <br />';
$i++;
}
echo '<input type="submit"/></form>';
//check of de form is verstuurd
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$nee = 0;
$ja = 0;
//tel de opties op
$t = 1;
while($t<=10){
if($_POST[$t] == 'nee'){
$nee = $nee + 1;
}
if($_POST[$t] == 'ja'){
$ja = $ja + 1;
}
$t++;
}
//kijken hoeveel ja's er zijn gegeven
if($ja < 5){
echo 'minder dan 5<br/>Aantal ja:'.$ja.'<br/>Aantal nee:'.$nee;
}elseif($ja > 5 && $ja < 8){
echo 'tussen 5 en 9<br/>Aantal ja:'.$ja.'<br/>Aantal nee:'.$nee;
}elseif($ja > 8 && $ja < 11){
echo 'tussen 9 en 10<br/>Aantal ja:'.$ja.'<br/>Aantal nee:'.$nee;
}else{
echo 'Aantal ja:'.$ja.'<br/>Aantal nee:'.$nee;
}
}
?>
(een klein voorbeeld je kan er zelf natuurlijk wat aan rommelen!)
Gewijzigd op 25/09/2012 19:15:10 door ScrapZz nl
Quote:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
echo '<form method="POST" action="">';
//Maak de opties aan
$i = 1;
while($i<=10){
echo 'Ja <input type="radio" name="'.$i.'" id="ja'.$i.'" value="ja" /> - Nee <input type="radio" name="'.$i.'" id="nee'.$i.'" value="nee" /> <br />';
$i++;
}
echo '<input type="submit"/></form>';
//check of de form is verstuurd
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$nee = 0;
$ja = 0;
//tel de opties op
$t = 1;
while($t<=10){
if($_POST[$t] == 'nee'){
$nee = $nee + 1;
}
if($_POST[$t] == 'ja'){
$ja = $ja + 1;
}
$t++;
}
//kijken hoeveel ja's er zijn gegeven
if($ja < 5){
echo 'Niet goed';
}elseif($ja > 5 && $ja < 8){
echo 'kan beter';
}elseif($ja > 8 && $ja < 11){
echo 'ok';
}else{
echo 'Aantal ja:';
}
}
?>
echo '<form method="POST" action="">';
//Maak de opties aan
$i = 1;
while($i<=10){
echo 'Ja <input type="radio" name="'.$i.'" id="ja'.$i.'" value="ja" /> - Nee <input type="radio" name="'.$i.'" id="nee'.$i.'" value="nee" /> <br />';
$i++;
}
echo '<input type="submit"/></form>';
//check of de form is verstuurd
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$nee = 0;
$ja = 0;
//tel de opties op
$t = 1;
while($t<=10){
if($_POST[$t] == 'nee'){
$nee = $nee + 1;
}
if($_POST[$t] == 'ja'){
$ja = $ja + 1;
}
$t++;
}
//kijken hoeveel ja's er zijn gegeven
if($ja < 5){
echo 'Niet goed';
}elseif($ja > 5 && $ja < 8){
echo 'kan beter';
}elseif($ja > 8 && $ja < 11){
echo 'ok';
}else{
echo 'Aantal ja:';
}
}
?>
Toevoeging op 25/09/2012 19:46:36:
ik heb het al gevonden!
bedankt iedereen voor de hulp!!!
Toevoeging op 25/09/2012 19:48:32:
hm, maar tussen de ja en nee moeten de verschillende vragen komen natuurlijk
Toevoeging op 25/09/2012 19:56:47:
ik hou het hierop, en proberen met css van de vierkantjes rondjs proberen te maken want ik wil een checkbox look
Quote:
<form action="form.php" method="post">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="7%">ja</td>
<td width="12%"> </td>
<td width="81%">nee</td>
</tr>
<tr>
<td><input name="antwoord[]" type="checkbox" class="checkbox"></td>
<td>vraag 1</td>
<td><input type="checkbox" name="nee" id="ja" value="1" /></td>
</tr>
<tr>
<td><input type="checkbox" name="antwoord[]"></td>
<td>vraag 2</td>
<td><input type="checkbox" name="nee" id="nee" value="2" /></td>
</tr>
<tr>
<td><input type="checkbox" name="antwoord[]"></td>
<td>vraag 3</td>
<td><input type="checkbox" name="nee" id="nee" value="3" /></td>
</tr>
<tr>
<td><input type="checkbox" name="antwoord[]"></td>
<td>vraag 4</td>
<td><input type="checkbox" name="nee" id="nee" value="4" /></td>
</tr>
<tr>
<td><input type="checkbox" name="antwoord[]"></td>
<td>vraag 5</td>
<td><input type="checkbox" name="nee" id="nee" value="5" /></td>
</tr>
<tr>
<td><input type="checkbox" name="antwoord[]"></td>
<td>vraag 6</td>
<td><input type="checkbox" name="nee" id="nee6" value="6" /></td>
</tr>
<tr>
<td><input type="checkbox" name="antwoord[]"></td>
<td>vraag 7</td>
<td><input type="checkbox" name="nee" id="nee" value="7" /></td>
</tr>
<tr>
<td><input type="checkbox" name="antwoord[]"></td>
<td>vraag 8</td>
<td><input type="checkbox" name="nee" id="nee" value="8" /></td>
</tr>
<tr>
<td><input type="checkbox" name="antwoord[]"></td>
<td>vraag 9</td>
<td><input type="checkbox" name="nee" id="nee" value="9" /></td>
</tr>
<tr>
<td><input type="checkbox" name="antwoord[]"></td>
<td>vraag 10</td>
<td><input type="checkbox" name="nee" id="nee" value="10" /></td>
</tr>
</table>
<input type="submit" value="GO"></form>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="7%">ja</td>
<td width="12%"> </td>
<td width="81%">nee</td>
</tr>
<tr>
<td><input name="antwoord[]" type="checkbox" class="checkbox"></td>
<td>vraag 1</td>
<td><input type="checkbox" name="nee" id="ja" value="1" /></td>
</tr>
<tr>
<td><input type="checkbox" name="antwoord[]"></td>
<td>vraag 2</td>
<td><input type="checkbox" name="nee" id="nee" value="2" /></td>
</tr>
<tr>
<td><input type="checkbox" name="antwoord[]"></td>
<td>vraag 3</td>
<td><input type="checkbox" name="nee" id="nee" value="3" /></td>
</tr>
<tr>
<td><input type="checkbox" name="antwoord[]"></td>
<td>vraag 4</td>
<td><input type="checkbox" name="nee" id="nee" value="4" /></td>
</tr>
<tr>
<td><input type="checkbox" name="antwoord[]"></td>
<td>vraag 5</td>
<td><input type="checkbox" name="nee" id="nee" value="5" /></td>
</tr>
<tr>
<td><input type="checkbox" name="antwoord[]"></td>
<td>vraag 6</td>
<td><input type="checkbox" name="nee" id="nee6" value="6" /></td>
</tr>
<tr>
<td><input type="checkbox" name="antwoord[]"></td>
<td>vraag 7</td>
<td><input type="checkbox" name="nee" id="nee" value="7" /></td>
</tr>
<tr>
<td><input type="checkbox" name="antwoord[]"></td>
<td>vraag 8</td>
<td><input type="checkbox" name="nee" id="nee" value="8" /></td>
</tr>
<tr>
<td><input type="checkbox" name="antwoord[]"></td>
<td>vraag 9</td>
<td><input type="checkbox" name="nee" id="nee" value="9" /></td>
</tr>
<tr>
<td><input type="checkbox" name="antwoord[]"></td>
<td>vraag 10</td>
<td><input type="checkbox" name="nee" id="nee" value="10" /></td>
</tr>
</table>
<input type="submit" value="GO"></form>
form.php