PHP ver gevorderde |
|
<?php
if(!is_numeric($_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{
if(isset($_POST['NumberOfOptions'])){ //If input was given, this should be written to a variable
$NumberOfOptions = $_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>";
}
for ($count = 1; $count <= $NumberOfOptions; $count++) { //Show the options that were just written down! - NOT WORKING YET
if (isset($_POST['question'.$count]) && !is_empty($_POST['question'.$count])) {
echo "<input type='radio' name='optie$count' value='$count'>". $_POST['question'.$count]."<br>";
}
}
}
?>
<?php if(!is_numeric($_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'>"; }else{ if(isset($_POST['NumberOfOptions'])){ //If input was given, this should be written to a variable $NumberOfOptions = $_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 } for ($count = 1; $count <= $NumberOfOptions; $count++) { //Show the options that were just written down! - NOT WORKING YET if (isset($_POST['question'.$count]) && !is_empty ($_POST['question'.$count])) { echo "<input type='radio' name='optie$count' value='$count'>". $_POST['question'.$count]."<br>"; } } } ?>
Je maakt het je eigen alleen maar moeilijk met het (edit:) NIET buiten de haakjes brengen van variabelen wanneer je ze gebruikt in een string. (edit:) Je zou dit WEL moeten doen. Je zou een keer moeten opzoeken hoe je variabelen best in strings gebruikt. |