I don't understand what the problem is, I'm left confused. I assume the problem might be very simple as I am new to PHP.
My form:
<form name="sentMessage" id="contactForm" novalidate> <div class="row control-group"> <label>Name</label> <div class="form-group col-xs-12 floating-label-form-group controls"> <input type="text" class="form-control" placeholder="Name" id="name" required data-validation-required-message="Please enter your name."> <p class="help-block text-danger"></p> </div> </div> <!-- Email Address --> <div class="row control-group"> <label>Email Address</label> <div class="form-group col-xs-12 floating-label-form-group controls"> <input type="email" class="form-control" placeholder="Email Address" id="email" required data-validation-required-message="Please enter your email address."> <p class="help-block text-danger"></p> </div> </div> <!-- Home Location --> <div class="row control-group"> <label>Home Location</label> <div class="form-group col-xs-12 floating-label-form-group controls"> <input type="text" class="form-control" placeholder="Home Location" id="homelocation" required data-validation-required-message="Please enter your home location."> <p class="help-block text-danger"></p> </div> </div> <!-- Phone Number --> <div class="row control-group"> <label>Phone Number</label> <div class="form-group col-xs-12 floating-label-form-group controls"> <input type="tel" class="form-control" placeholder="Phone Number" id="phone" required data-validation-required-message="Please enter your phone number."> <p class="help-block text-danger"></p> </div> </div> <div class="row control-group"> <label>How did you hear about us?</label><br> <div class="form-group col-xs-12 floating-label-form-group controls"> <select name="advert" <!-- To configure -->> <option value="google">Google Search</option> <option value="trademe">Trademe</option> </select> <p class="help-block text-danger"></p> </div> </div> JS:
submitSuccess: function($form, event) { // Prevent spam click and default submit behaviour $("#btnSubmit").attr("disabled", true); event.preventDefault(); // get values from FORM var name = $("input#name").val(); var email = $("input#email").val(); var phone = $("input#phone").val(); var homelocation = $("input#homelocation").val(); .... $.ajax({ url: "././mail/contact_me.php", type: "POST", data: { name: name, phone: phone, email: email, homelocation: homelocation, ......... and my php:
<?php // Check for empty fields if(empty($_POST['name']) || empty($_POST['email']) || empty($_POST['phone']) || empty($_POST['homelocation']) || !filter_var($_POST['email'],FILTER_VALIDATE_EMAIL)) { echo "No arguments Provided!"; return false; } $name = strip_tags(htmlspecialchars($_POST['name'])); $email_address = strip_tags(htmlspecialchars($_POST['email'])); $phone = strip_tags(htmlspecialchars($_POST['phone'])); $homelocation = strip_tags(htmlspecialchars($_POST['homelocation'])); .............. The code works perfectly fine if I comment out homelocation, I have no idea why.
I am new to PHP so I am a bit confused as to why the above code doesn't work, but if homelocation is commented out, then it works. The name and homelocation have the same input type, so I don't think data type has anything to do with it, and I am sure the variable names are used correctly, could someone please point me to the right direction on this one.
Thanks!
homelocationpass or not in consolehomelocationfield?emptyornull? You have this fieldempty($_POST['homelocation'])You may want to pass default value ifhomelocationis empty.