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 8808071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:31:39+00:00 2026-06-14T02:31:39+00:00

The contact form it´s working, if you fill it all it sends the message.

  • 0

The contact form it´s working, if you fill it all it sends the message. The problem if you don´t fill in the email box, the form doesn´t alert you about it, is there anyway that I can show a word or somekind of alert to the user?

this is my markup:

<div class="form">
        <h2>ESCRIBENOS</h2>
        <form method="post" action="process.php">
        <div class="element">
            <label>Nombre (obligatorio):</label><br/>
            <input type="text" name="name" class="text" />
        </div>
        <div class="element">
            <label>Email (obligatorio):</label><br/>
            <input type="text" name="email" class="text" />
        </div>
        <div class="element">
            <label>Telefono:</label><br/>
            <input type="text" name="website" class="text" />
        </div>
        <div class="element">
            <label>Mensaje:</label><br/>
            <textarea name="comment" class="text textarea" /></textarea>
        </div>
        <div class="element">

            <input type="submit" id="submit"/>
            <div class="loading"></div>
        </div>
        </form>
        </div>

And this is my script:

$(document).ready(function() {

//if submit button is clicked
$('#submit').click(function () {        

    //Get the data from all the fields
    var name = $('input[name=name]');
    var email = $('input[name=email]');
    var website = $('input[name=website]');
    var comment = $('textarea[name=comment]');

    //Simple validation to make sure user entered something
    //If error found, add hightlight class to the text field
    if (name.val()=='') {
        name.addClass('hightlight');
        return false;
    } else name.removeClass('hightlight');

    if (email.val()=='') {
        email.addClass('hightlight');
        return false;
    } else email.removeClass('hightlight');

    if (comment.val()=='') {
        comment.addClass('hightlight');
        return false;
    } else comment.removeClass('hightlight');

    //organize the data properly
    var data = 'name=' + name.val() + '&email=' + email.val() + '&website=' + 
    website.val() + '&comment='  + encodeURIComponent(comment.val());

    //disabled all the text fields
    $('.text').attr('disabled','true');

    //show the loading sign
    $('.loading').show();

    //start the ajax
    $.ajax({
        //this is the php file that processes the data and send mail
        url: "../process.php",  

        //GET method is used
        type: "GET",

        //pass the data         
        data: data,     

        //Do not cache the page
        cache: false,

        //success
        success: function (html) {              
            //if process.php returned 1/true (send mail success)
            if (html==1) {                  
                //hide the form
                $('.form').fadeOut('slow');                 

                //show the success message
                $('.done').fadeIn('slow');

            //if process.php returned 0/false (send mail failed)
            } else alert('Sorry, unexpected error. Please try again later.');               
        }       
    });

    //cancel the submit button default behaviours
    return false;
}); 
}); 

Can someone help me out please?

  • 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-14T02:31:42+00:00Added an answer on June 14, 2026 at 2:31 am

    Try this:

    var name = $('input[name=name]');
            var email = $('input[name=email]');
            var website = $('input[name=website]');
            var comment = $('textarea[name=comment]');
    
            //Simple validation to make sure user entered something
            //If error found, add hightlight class to the text field
    
            $('input[type=text]').each(function(){
                 if($(this).val().length == 0){
                    $(this).addClass('hightlight');
                    alert('Empty input field')
                    return false;
                 }
            });
    

    …. rest of your code

    Note: This does not work for textarea but I think you can figure that out yourself!


    EDIT:

      var valid = false;
    
        $('input[type=text]').each(function(){
                 if($(this).val().length == 0){
                    $(this).addClass('hightlight');
                    alert('Empty input field')
                    valid = false;
                 }else{
                    valid = true;
                 }
            });
    
    
        if(valid == false) return; 
            console.log('All input fields are filled in..');
    

    … rest of your code. You can remove al the if else statements for input fields. For checking the textarea you could give all fields the same class and do:

    $('form.classofallelements').each(function(){
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

having a problem getting my simple php email contact form working. No errors are
My contact form is not working and I cant find the bug at all.
I am working on a contact form. Now I am having a problem when
I'm coding my first ever PHP contact form. I've been working on it all
Hi all i have a contact form and captcha is there. i want keep
I am working on a simple contact form written in php and have almost
I'm working on a contact form for my church website. The church has an
I'm building a contact form that appears in a jQuery popup box. When you
I have a contact form made with php on my website. The problem is
I have a contact form which asks users for their name, email address and

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.