Script loop terug van boven af door wegens foutief criterium
Ik geef in het begin een criterium op (!ctype...), maar als ik mijn twee form submit, dan is NumberOfOptions niet meer ingevuld. DUS loopt hij het scriptje weer van boven af aan door. Ik heb al wat gerommeld met sessions, maar kom er niet uit. Kan iemand even helpen?
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
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
<?php
if(!ctype_digit($_POST['NumberOfOptions'])){ //If numerical input was given, don't show the form
echo "Vul hieronder het aantal antwoorden in:<br />";
echo "<form action='poll_array.php' method='post'>";
echo "<input type='text' name='NumberOfOptions'>";
echo "<input type='submit' value='Maak poll'>";
echo "</form>";
}
else {
$NumberOfOptions = (int)$_POST['NumberOfOptions'];
if ($NumberOfOptions <= 1){ //Check for at least 2 answers.
echo 'Kies minstens twee opties.';
}
else {
echo '<div id="ShowOptions">';
echo "<form action='poll_array.php' method='post'>";
echo "Vul hieronder de antwoorden in:<br />";
for($count = 1; $count <= $NumberOfOptions; $count++) {//Print desired amount of input options
echo "Antwoord optie #".$count.": <input name='question[$count]' type='text'><br />";
}
echo "<input type='submit' value='Submit optie'>"; //Remember the given options
echo "</form>";
echo "</div>";
}
if(!empty($_POST['questions']) && empty($_POST['NumberOfOptions'])){
echo "hello";
}
}
?>
if(!ctype_digit($_POST['NumberOfOptions'])){ //If numerical input was given, don't show the form
echo "Vul hieronder het aantal antwoorden in:<br />";
echo "<form action='poll_array.php' method='post'>";
echo "<input type='text' name='NumberOfOptions'>";
echo "<input type='submit' value='Maak poll'>";
echo "</form>";
}
else {
$NumberOfOptions = (int)$_POST['NumberOfOptions'];
if ($NumberOfOptions <= 1){ //Check for at least 2 answers.
echo 'Kies minstens twee opties.';
}
else {
echo '<div id="ShowOptions">';
echo "<form action='poll_array.php' method='post'>";
echo "Vul hieronder de antwoorden in:<br />";
for($count = 1; $count <= $NumberOfOptions; $count++) {//Print desired amount of input options
echo "Antwoord optie #".$count.": <input name='question[$count]' type='text'><br />";
}
echo "<input type='submit' value='Submit optie'>"; //Remember the given options
echo "</form>";
echo "</div>";
}
if(!empty($_POST['questions']) && empty($_POST['NumberOfOptions'])){
echo "hello";
}
}
?>
session_start();
staan?
Lars
Toevoeging op 24/08/2010 22:26:20:
Heb je bij dat $_SESSION probeersel ook HELEMAAL bovenaan:
session_start();
staan?
Lars
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
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
<?php
session_start();
if(!ctype_digit($_POST['NumberOfOptions']) && !isset($_SESSION['views']) ){ //If numerical input was given, don't show the form
echo "Vul hieronder het aantal antwoorden in:<br />";
echo "<form action='poll_array.php' method='post'>";
echo "<input type='text' name='NumberOfOptions'>";
echo "<input type='submit' value='Maak poll'>";
echo "</form>";
}
else {
$NumberOfOptions = (int)$_POST['NumberOfOptions'];
if ($NumberOfOptions <= 1){ //Check for at least 2 answers.
echo 'Kies minstens twee opties.';
}
else {
$_SESSION['views'] = 1;
echo '<div id="ShowOptions">';
echo "<form action='poll_array.php' method='post'>";
echo "Vul hieronder de antwoorden in:<br />";
for($count = 1; $count <= $NumberOfOptions; $count++) {//Print desired amount of input options
echo "Antwoord optie #".$count.": <input name='question[$count]' type='text'><br />";
}
echo "<input type='submit' value='Submit optie'>"; //Remember the given options
echo "</form>";
echo "</div>";
}
if(!empty($_POST['questions'])){
echo "hello";
}
}
?>
session_start();
if(!ctype_digit($_POST['NumberOfOptions']) && !isset($_SESSION['views']) ){ //If numerical input was given, don't show the form
echo "Vul hieronder het aantal antwoorden in:<br />";
echo "<form action='poll_array.php' method='post'>";
echo "<input type='text' name='NumberOfOptions'>";
echo "<input type='submit' value='Maak poll'>";
echo "</form>";
}
else {
$NumberOfOptions = (int)$_POST['NumberOfOptions'];
if ($NumberOfOptions <= 1){ //Check for at least 2 answers.
echo 'Kies minstens twee opties.';
}
else {
$_SESSION['views'] = 1;
echo '<div id="ShowOptions">';
echo "<form action='poll_array.php' method='post'>";
echo "Vul hieronder de antwoorden in:<br />";
for($count = 1; $count <= $NumberOfOptions; $count++) {//Print desired amount of input options
echo "Antwoord optie #".$count.": <input name='question[$count]' type='text'><br />";
}
echo "<input type='submit' value='Submit optie'>"; //Remember the given options
echo "</form>";
echo "</div>";
}
if(!empty($_POST['questions'])){
echo "hello";
}
}
?>
Gewijzigd op 25/08/2010 11:44:13 door ewergreen php