Liam Liam - 11 months ago 51
Javascript Question

AJAX Form submission error

I have a form that I want to validate on submission.

I have the following javascript...

var data = $('.sighting').serialize();
$.ajax({ url: "submit-process.php",
data: data,
type: "POST",
success: function(data){
$(".result").text('Thank you for your assistance.');
error: function(data) {

And I have the following PHP

if('date-seen' == '') {
echo 'fail'
} else {
foreach ($_POST as $key => $value)
$message .= "Field ".htmlentities($key)." is ".htmlentities($value)."\r\n";

mail('', 'sghting', $message);

If the 'date-seen' input is left blank, I receive [Object, object] instead of 'fail' only then if I fill in this field and try resending It doesnt submit, which im guessing is an error in my PHP?

Any help would be brilliant, thanks.


'date-seen' == '' tests if two string literals are equal to each other (and they aren't).

You probably want $_POST['date-seen']

You also probably want to make your test:

if ( !empty($_POST['date-seen']) ) {

...instead of comparing a variable that does not exist to an empty string.