I created a form with a select drop-down list that effect the other one. I mean, the choice in the first drop-down list effect the data in the other drop-down list. I did it using Json and jQuery.
The problem is that I can not get the dorm details by email. it doesn't work.
The json file is:
{
"health":[
["1","Biorgonomi"],
["2","Diet and Weight Loss"],
["3","Lasik"],
["4","Smoking Cessation"],
["5","Body Lines"],
["6","Treatment of hemorrhoids"],
["7","Treatment of snoring"],
["8","personal trainer"],
["9","Gyms"],
["10","hearing aid"],
["11","Nail Fungus"],
["12","Pilates"]
],
"mercedes":[
["13","class A"],
["14","class B"],
["15","class C"],
["16","class E"]
],
"audi":[
["17","a3"],
["18","a4"],
["19","a5"],
["20","a6"]
],
"volswagen":[
["21","polo"],
["22","golf"],
["23","cady"]
]
}
The jQuery file is:
jQuery().ready(function(){
var tabMarque=[];
$.getJSON('http://thewebsite.com/wp-content/themes/Avada/js/healthandbeauty/healthandbeautydetails.json', function(data) {
$.each(data, function(index, val) {
tabMarque[index]=val;
});
});
$('#Marque').change(function(event) {
$marque=$(this).val();
$htmlOption='<option value="0">Choix du serie</option>';
if($marque!=0)
{
$.each(tabMarque[$marque], function(key, value) {
$htmlOption+='<option value="'+value[0]+'">'+value[1]+'</option>';
});
}
$('#Serie').html($htmlOption);
});
});
The html form :
<form action="http://thewebsite.com/wp-content/themes/Avada/js/healthandbeauty/js/send_to_email.php" method="get">
<select id="Marque">
<option value="0">CAR COMPANY</option>
<option value="health">health</option>
<option value="mercedes">mercedes</option>
<option value="audi">audi</option>
<option value="volswagen">volswagen</option>
</select>
<select id="Serie"></select>
<select id="Location">
<option value="0">Your Location</option>
<option value="Elondon">East London</option>
<option value="nlondon">North London</option>
<option value="wlondon">West London</option>
<option value="slondon">South London</option>
</select>
<input name="vemail" placeholder="Your Email" type="text" value="">
<input id="send" name="submit" type="submit" value="Send">
</form>
The php file that send the details to my email :
<?php
if(isset($_POST["submit"])){
// Checking For Blank Fields..
if($_POST["Marque"]==""||$_POST["vemail"]==""||$_POST["Serie"]==""||$_POST["Location"]==""){
echo "Fill All Fields..";
}else{
// Check if the "Sender's Email" input field is filled out
$email=$_POST['vemail'];
// Sanitize E-mail Address
$email =filter_var($email, FILTER_SANITIZE_EMAIL);
// Validate E-mail Address
$email= filter_var($email, FILTER_VALIDATE_EMAIL);
if (!$email){
echo "Invalid Sender's Email";
}
else{
$subject = $_POST['Marque'];
$message = $_POST['Serie'];
$location= $_POST['Location'];
$headers = 'From:'. $email2 . "
"; // Sender's Email
$headers .= 'Cc:'. $email2 . "
"; // Carbon copy to Sender
// Message lines should not exceed 70 characters (PHP rule), so wrap it
$message = wordwrap($message, 70);
// Send Mail By PHP Mail Function
mail("myemail@xyz.com", $subject, $message, $headers, $location);
echo "Your mail has been sent successfuly ! Thank you for your feedback";
}
}
}
?>