php cannot validate if fields are set
You conditions in PHP file are wrong. Use this instead
if(isset($_POST['name']) && isset($_POST['email']) && isset($_POST['order'])) { $data = array('message' => "Message A"); echo json_encode($data);}else{ $data = array('message' => "All fields are required"); echo json_encode($data);}
I use &&
for required values. You can use &&
or ||
according to your need.
Update
if(!isset($_POST['name']) || !isset($_POST['email']) || !isset($_POST['order'])) { $data = array('message' => "All fields are required"); echo json_encode($data);}else{ // whatever you want to do, if all values available, goes here}