Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8026021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:21:10+00:00 2026-06-04T23:21:10+00:00

I need some help with getting JQuery AJAX to work with a method in

  • 0

I need some help with getting JQuery AJAX to work with a method in one of my PHP classes. I validated the form using a PHP class and which extends a Database class. I just need the AJAX to work and I’m good. How do you get AJAX to work with OO PHP? I have been stuck on this for the past few days and have researched all across the internet and have not found anything that works. Can someone maybe post a simple example of getting JQuery’s AJAX function to work with a PHP method?

Here is the PHP method that returns whether the user passed validation or not (contact.class.php which extends database.class.php):

public function isValidData() {

if ($this -> firstName() && $this -> lastName() && $this -> email() && $this -> subject() && $this -> message()) {

        return true;
    } else {
        return false;
    }

}

Here is the Jquery. The Ajax is at the bottom:

//Submit function called when the user clicks the submit button

$('#contact_form').submit(function(e) {

    //Prevent submission until the user passes validation
    e.preventDefault();

    //If all the functions return true, then send form to the AJAX function
    if(validFirstName() && validLastName() && validEmail() && validSubject() && validMessage()) {
        //Serialize the data in the form for the AJAX Request
        var formData = $('#contact_form').serialize();

        //submitForm(formData);
        //Displays success message, clears contact form and hides the lightbox
        $('#contact_form').fadeOut(1000, function() {
            $('.success').html('Form submission successful.' + '<br/>' + 'Thank you ' + $('input.first').val() + "!").fadeIn(4000, function() {
                //Clears contact form
                $('.first').val('');
                $('.last').val('');
                $('.email').val('');
                $('.subject').val('');
                $('.message').val('');
                //Hides success message
                $('.success').hide();
                //Hides lightbox
                $('.mask, .main_contact').css('display', 'none');
            });

        });
        return true;

    } else {
        return false;
    }

});

//Validates the user's first name
function validFirstName() {
    var firstName = $('.first').val();
    if(firstName.length <= 2 || firstName == '') {
        $('.error').show().html('3 Characters required!<br/>');
        $('.first').css('box-shadow', ' 0 0 10px #B40404');
        return false;
    } else {
        $('.first').css('box-shadow', '0 0 4px #000');
        $('.error').hide();
        return true;
    }

}

//Validates the user's last name
function validLastName() {
    var lastName = $('input.last').val();
    if(lastName.length <= 2 || lastName == '') {
        $('.error').show().html('3 Characters required!<br/>');
        $('input.last').css('box-shadow', '0 0 10px #B40404');
        return false;

    } else {
        $('input.last').css('box-shadow', '0 0 4px #000');
        $('.error').hide();
        return true;
    }
}

//Validates the user's email
function validEmail() {
    var email = $('.email').val();
    if(!email.match(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/)) {
        $('.error').show().html('Invalid email address!<br/>');
        $('.email').css('box-shadow', ' 0 0 10px #B40404');
        return false;

    } else {
        $('.email').css('box-shadow', '0 0 4px #000');
        $('.error').hide();
        return true;
    }

}

//Validate the subject input in the contact form
function validSubject() {
    var subject = $('.subject').val();
    if(subject.length <= 2 || subject == '') {
        $('.error').show().html('3 Characters required!<br/>');
        $('.subject').css('box-shadow', ' 0 0 10px #B40404');
        return false;
    } else {
        $('.subject').css('box-shadow', '0 0 4px #000');
        $('.error').hide();
        return true;
    }
}

//Validate the message input
function validMessage() {

    var message = $('.message').val();
    if(message.length <= 2 || message == '') {
        $('.error').show().html('3 Characters required!<br/>');
        $('.message').css('box-shadow', ' 0 0 10px #B40404');
        return false;
    } else {
        $('.message').css('box-shadow', '0 0 4px #000');
        $('.error').hide();
        return true;
    }

}

 });

//Ajax Request

function submitForm(formData) {

$.ajax({
    type : "POST",
    url : "includes/function.php",
    data : formData,
    dataType: 'json',
    cache : false,
    success : function(formData) {
        if(formData.success) {

            alert(formData.msg);
        } else {
            alert("Error");
        }
        console.log(formData);

    }
});

The Jquery seems to disable my PHP serverside validation too. When the JQuery is disabled, the server side validation works fine. Any idea why JQuery would disable the server validation? I am kinda new to programming and I would appreciate any help, thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T23:21:12+00:00Added an answer on June 4, 2026 at 11:21 pm

    the jquery is client side validation it cannot affect server side execution, the problem is the serialized data is not getting posted to the server hence the validation at server is not done because no data is reaching there.

    why don’t u use alert at every step to see the flow of data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some help getting the jquery cycle plugin to work as below: Basically,
i need some help for getting my statics work... I use core data to
I'm currently using json-framework and need some help though parsing some JSON i'm getting
I need some help getting a serialized <ul> list submitted via a AJAX post
I need some help in getting started with jQuery and autocompleting a username for
I need some help getting data from several tables. This is the tables I
I need some help in understanding what is happening here .I am getting a
I need some help. Here's what I'm getting right now: img ref I need
Need some help, please. I have a line of horizontal thumbnails loaded as ONE
I need some help with my jQuery script. I have a page that refreshes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.