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

  • Home
  • SEARCH
  • 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 7517633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:30:58+00:00 2026-05-30T01:30:58+00:00

I am creating a comment form based on the jquery validation plugin (http://docs.jquery.com/Plugins/Validation). I

  • 0

I am creating a comment form based on the jquery validation plugin (http://docs.jquery.com/Plugins/Validation). I know that javascript can easily be manipulated by hackers, so I was wondering how to validate via php to insure that the comment form does not generate a lot of spam emails?

The js is directly from the validation plugin. The html form is directly from the JS validation plugin page. The additional js is below:

  <script>
  $(document).ready(function(){
  $("#commentForm").submit(function(){
    if($("#commentForm").validate()){
        $.ajax({
            type: 'POST',
            url: 'process.php',
            data: $(this).serialize(),
            success: function(returnedData){
                alert(returnedData);
            }
        });
    }
    return false;
});
});
  </script>

<form class="cmxform" id="commentForm" method="POST" action="process.php">
   <label for="cname">Name</label>
   <input id="cname" name="name" size="25" class="required" minlength="2" />
   <label for="cemail">E-Mail</label>
   <input id="cemail" name="email" size="25"  class="required email" />
   <label for="curl">URL</label>
   <input id="curl" name="url" size="25"  class="url" value="" />
   <label for="ccomment">Your comment</label>
   <textarea id="ccomment" name="comment" cols="22"  class="required"></textarea>
<input class="submit" type="submit" value="Submit"/>

The php is pretty standard currently. Not sure how to integrate the validation with js and ajax:

<?php

$to      = 'sdfsadfssfasd@gmail.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com';

mail($to, $subject, $message, $headers);

print "Form submitted successfully: <br>Your name is <b>".$_POST['cname']."</b> and your email is <b>".$_POST['email']."</b><br>";
?>

Thanks for any help. Someone has commented that this is vague. To clarify:

I understand how to use php to validate email length, unnecessary characters, etc. I do not understand how the jquery validation plugin works via ajax. I need to know how to configure my php conditionals to properly validate the comment form to protect against spam.

  • 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-05-30T01:31:00+00:00Added an answer on May 30, 2026 at 1:31 am

    Ok the way you do this is pretty straight forward.
    So you have a submit function, but before you actually send a request to the .php file, you need to validate the input. Your code is pretty sound so far, but you need to start with the validate function. That could look something like this(in jQuery). Let’s say that your input fields have the following id: #input1,#input2,#input3,#input4.

        function validate()
    {
        if($('#input1).val()=='' || $('#input2).val()==''|| $('#input3).val()=='' $('#input4).val()=='') return 0;
        else return 1;
    
    }
    

    This would be the most basic way to use validation. If you don’t want jQuery, you could replace $(‘#input1) with docoument.getElementById(the old fashioned way). If you also want to make it look nice for the user, you could validate each input field on blur!
    For instance, let’s assume the user focuses on the first input field, #input1

    $('#input1).focus(function(){change the background color,add a border, or anything you want just to let the users see which input they clicked/tabbed on.}).blur(function(){check if the input is valid and if it's not display a message or anything you want.});
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a comment form based on the jquery validation plugin ( http://docs.jquery.com/Plugins/Validation
I am creating a JavaScript / ajax comment form using the jQuery Validation Plugin.
I'm doing this tutorial: http://www.phpeveryday.com/articles/Zend-Framework-Database-Creating-Input-Form-P494.html We are building a simple input form using POST
Right now i been creating a form for a comment section, a Login section,
I'm creating comment fields which are based on user input into textarea. But when
I was trying to hit a web service using the instructions here: http://help.seeclickfix.com/kb/api/creating-an-issue I
I'm quite anal about form validation. So while creating a validator for a data
I am using the jQuery inline form validation to validate my form. my form
(creating a separate question after comments on this: Javascript redeclared global variable overrides old
Creating liquid layouts is an immense pain. Now, I totally understand that tables should

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.