Hello everybody! I’m new here, and also new in PHP. I hope someone can help me with this problem:
I have a form in php for people who may choose 2 toys for their kids, problem is they can not choose twice the same thing per child. So i’m really hoping some of you could help me out here! (there should be a warning when one child gets the same choise twice)
here is my code:
[php]<?php
$EmailFrom = “[email protected]”;
$EmailTo = “[email protected]”;
$Subject = “Toys 2012”;
$Name = Trim(stripslashes($_POST[‘Name’]));
$Voornaam = Trim(stripslashes($_POST[‘Lastname’]));
$Email = Trim(stripslashes($_POST[‘Email’]));
$Child1 = Trim(stripslashes($_POST[‘Child1’]));
$Child2 = Trim(stripslashes($_POST[‘Child2’]));
$Child3 = Trim(stripslashes($_POST[‘Child3’]));
$Child4 = Trim(stripslashes($_POST[‘Child4’]));
$Child1Choise1 = Trim(stripslashes($_POST[‘Child1Choise1’]));
$Child1Choise2 = Trim(stripslashes($_POST[‘Child1Choise2’]));
$Child2Choise1 = Trim(stripslashes($_POST[‘Child2Choise1’]));
$Child2Choise2 = Trim(stripslashes($_POST[‘Child2Choise2’]));
$Child3Choise1 = Trim(stripslashes($_POST[‘Child3Choise1’]));
$Child3Choise2 = Trim(stripslashes($_POST[‘Child3Choise2’]));
$Child4Choise1 = Trim(stripslashes($_POST[‘Child4Choise1’]));
$Child4Choise2 = Trim(stripslashes($_POST[‘Child4Choise2’]));
$Aantal = Trim(stripslashes($_POST[‘Party’]));
//validation
$validationOK=true;
if (!$validationOK) {
print “<meta http-equiv=“refresh” content=“0;URL=error.htm”>”;
exit;
}
//email
$Body = “”;
$Body .= "Name: ";
$Body .= $Name;
$Body .= “\n”;
$Body .= "Last name: ";
$Body .= $Lastname;
$Body .= “\n”;
$Body .= "Email: ";
$Body .= $Email;
$Body .= “\n”;
$Body .= “\n”;
$Body .= "Child 1: ";
$Body .= $Child1;
$Body .= “\n”;
$Body .= "Choise 1: ";
$Body .= $Child1Choise1;
$Body .= “\n”;
$Body .= "Choise 2: ";
$Body .= $Child1Choise2;
$Body .= “\n”;
$Body .= “\n”;
$Body .= "Child 2: ";
$Body .= $Child2;
$Body .= “\n”;
$Body .= "Choise 1: ";
$Body .= $Child2Choise1;
$Body .= “\n”;
$Body .= "Choise 2: ";
$Body .= $Child2Choise2;
$Body .= “\n”;
$Body .= “\n”;
$Body .= "Child 3: ";
$Body .= $Child3;
$Body .= “\n”;
$Body .= "Choise 1: ";
$Body .= $Child3Choise1;
$Body .= “\n”;
$Body .= "Choise 2: ";
$Body .= $Child3Choise2;
$Body .= “\n”;
$Body .= “\n”;
$Body .= "Child 4: ";
$Body .= $Child4;
$Body .= “\n”;
$Body .= "Choise 1: ";
$Body .= $Child4Choise1;
$Body .= “\n”;
$Body .= "Choise 2: ";
$Body .= $Child4Choise2;
$Body .= “\n”;
$Body .= “\n”;
$Body .= “\n”;
$Body .= "Number on party: ";
$Body .= $Party;
// send email
$email_valid= filter_var( $_POST[‘Email’], FILTER_VALIDATE_EMAIL );
if( $email_valid != false && !empty( $Voornaam ) )
{
$success = mail($EmailTo, $Subject, $Body, “From: <$EmailFrom>”);
}
else
{
$error = ‘Please fill in your name and correct email!’;
}
// redirect
if ($success){
print “<meta http-equiv=“refresh” content=“0;URL=contactthanks.php”>”;
}
else{
print “<meta http-equiv=“refresh” content=“0;URL=error.html”>”;
}
?>[/php]
Thank you guys very much!!
Greetings from Belgium!