I am working on a form for my school that will have 3 questions with dropdown menus and then a submit button.
What the form needs to do is when all 3 questions are answered, then redirect to a other url.
so, for example:
if all 3 questions are answered with the first answer in the dropdown menu, the visitor will be redirected to url 1 but if all 3 questions are answered with the second answer in the dropdown menu, the visitor will be redirected to url 2 url 3 url 4 etc.
I tried a lot of possible ways, but none have works.
I hope someone can help me,
thanks in advance
Thomas
here is my code if it helps to understand my question (I know it is not the most proffesional one, and some of the text is in dutch for the form itself)
<!DOCTYPE HTML>
<html>
<head>
<style>
.error {color: #FF0000;}
</style>
</head>
<body>
<?php
// define variables and set to empty values
$nameErr = $emailErr = $genderErr = $websiteErr = "";
$name = $email = $gender = $comment = $website = "";
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
if (empty($_POST["name"])) {
$nameErr = "Naam is vereist";
} else {
$name = test_input($_POST["name"]);
// check if name only contains letters and whitespace
if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
$nameErr = "Alleen letters en spaties toegestaan";
}
}
if (empty($_POST["email"])) {
$emailErr = "Email is vereist";
} else {
$email = test_input($_POST["email"]);
// check if e-mail address is well-formed
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$emailErr = "Geen geldig E-mail";
}
}
if (!isset($_POST["Ik_wil_graag_bijles"])) {
$q1Err = "Je bent vergeven in te vullen of je bijles wilt krijgen of geven";
}
if (!isset($_POST["In_het_vak"])) {
$q2Err = "Je bent vergeven een vak in te vullen";
}
if (!isset($_POST["Ik_ben_Ik_wil_graag_op_niveau"])) {
$q3Err = "Je bent vergeven een niveau in te vullen";
}
// doorverwijzingen
if(isset($_POST['Submit']) == true)
{
if($_POST['Ik_wil_graag_bijles']) == 1) && ($_POST['In_het_vak']) == 1) && ($_POST['Ik_ben_Ik_wil_graag_op_niveau']) == 1)
{
//link Krijgen Arduino Beginner
header('Location: http://www.google.com');
exit();
}
if($_POST['Ik_wil_graag_bijles']) == 1) && ($_POST['In_het_vak']) == 2) && ($_POST['Ik_ben_Ik_wil_graag_op_niveau']) == 1)
{
//link Krijgen elektro Beginner
}
if($_POST['Ik_wil_graag_bijles']) == 1) && ($_POST['In_het_vak']) == 3) && ($_POST['Ik_ben_Ik_wil_graag_op_niveau']) == 1)
{
//link Krijgen statica Beginner
}
if($_POST['Ik_wil_graag_bijles']) == 1) && ($_POST['In_het_vak']) == 4) && ($_POST['Ik_ben_Ik_wil_graag_op_niveau']) == 1)
{
//link Krijgen sterkteleer Beginner
}
if($_POST['Ik_wil_graag_bijles']) == 1) && ($_POST['In_het_vak']) == 5) && ($_POST['Ik_ben_Ik_wil_graag_op_niveau']) == 1)
{
//link Krijgen wiskunde Beginner
}
}
// mail naar educacie
if(isset($_POST['Submit']) == true)
{
$to = "dacovh@gmail.com";
$from = $_POST['email'];
$naam = $_POST['naam'];
$q1 = $_POST['Ik_wil_graag_bijles'];
$q2 = $_POST['In_het_vak'];
$q3 = $_POST['Ik_ben_Ik_wil_graag_op_niveau'];
$subject = "nieuwe inschrijving";
$message = $naam "wil graag bijles" $q1 "in het vak" $q2 ". Hij/zij is" $q3 "of wilt op dit niveau bijles."
$headers = "From:" . $from;
mail($to,$subject,$message,$headers)
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<h2>Bijles Formulier</h2>
<p><span class="error">* vereisde velden.</span></p>
<form name="registerform" id="registerform" method="post">
Naam: <input type="text" name="naam" value="<?php echo $name;?>">
<span class="error">* <?php echo $nameErr;?></span>
<br><br>
E-mail: <input type="text" name="email" value="<?php echo $email;?>">
<span class="error">* <?php echo $emailErr;?></span>
<br><br>
<p>
Ik wil graag bijles ... :
<span class="error">* <?php echo $q1Err;?></span>
<select name="Ik_wil_graag_bijles">
<option value=""> selecteer </option>
<option value="1">krijgen</option>
<option value="2">geven</option>
</select>
</p>
<p>
In het vak ... :
<span class="error">* <?php echo $q2Err;?></span>
<select name="In_het_vak">
<option value=""> selecteer </option>
<option value="1">Arduino</option>
<option value="2">Elektro-techniek</option>
<option value="3">Statica</option>
<option value="4">Sterkteleer</option>
<option value="5">Wiskunde</option>
</select>
</p>
<p>
Ik ben ... / Ik wil graag op ... niveau:
<span class="error">* <?php echo $q3Err;?></span>
<select name="Ik_ben_Ik_wil_graag_op_niveau">
<option value=""> selecteer </option>
<option value="1">Beginner</option>
<option value="2">Gevorderde</option>
<option value="3">Expert</option>
</select>
</p>
<input type="submit" name="submit" value="Indienen">
</form>
</body>
</html>
Aucun commentaire:
Enregistrer un commentaire