php cannot validate if fields are set php cannot validate if fields are set json json

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}


Try this:

<?php if(!isset($_POST['name']) || !isset($_POST['email']) || !isset($_POST['order'])) {    echo "No post values found!";}else{    $data = array('message' => "Message A");    echo json_encode($data);}?>


Instead of using !isset() try using empty().