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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:35:08+00:00 2026-06-03T04:35:08+00:00

I have a submit button in a form and use PHP for scripting to

  • 0

I have a submit button in a form and use PHP for scripting to email the form. When the button is pressed nothing happens, not even showing the PHP code like when PHP isn’t installed. I have tested other simple mailing forms on machine and they show the code. This one does nothing.

HTML Code:

<form name="apply" method="post" action="mail.php">                 
<font class="error-message"></font>
    <div class="form-content">
        <div class="left-label">
            <label>First and Last name:</label>
            <label>School type:</label>
            <label>Practice name:</label>
            <label class="address">Address:</label>
    <label class="address2">Address (cont):</label>
    <label class="zip">Zip Code:</label>
    <label class="city">City:</label>
            <label>Website:</label>
            <label>Email:</label>
        </div>
        <div class="right-fields">                          
            <input type="text" name="fist-last-name" placeholder="First & Last name" title="Please enter First & Last name." />
            <select name="select-school">
                <option>--select--</option>
                <option>Dental Assistant School</option>
                <option>Medical Assistant School</option>
                <option>Pharmacy Technician School</option>
                <!-- <option>Personal Trainer School</option> -->
                <option>Other School</option>
            </select>
            <input type="text" name="practice-name" placeholder="Practice name" title="Please enter your practice name." />
            <textarea name="address1" placeholder="Address 1" title="Please enter address1"></textarea>
            <textarea name="address2" placeholder="Address 2" title="Please enter address2"></textarea>
            <div class="clear"></div>
            <input type="text" name="zipcode" placeholder="Zip Code" title="Please enter your zipcode." /><br>
            <input type="text" name="city" placeholder="City" title="Please enter the city where you live." />
            <input type="text" name="website-address" placeholder="Website" title="Please enter your website address." />
            <input type="text" name="email" placeholder="Email" title="Please enter your email address." />
            <input type="submit" value="Submit"/>
        </div>
    </div>
    <div class="clear"></div>
</form>

PHP code, mail.php:

<?php

$fist_last_name     = $_POST["fist-last-name"];

$school_type        = $_POST["select-school"];

$practice_name      = $_POST["practice-name"];

$address1           = $_POST["address1"];

$address2           = $_POST["address2"];

$zipcode            = $_POST["zipcode"];

$city               = $_POST["city"];

$website            = $_POST["website-address"];

$email              = $_POST["email"];


$body   = " <table>

                <tr><th>First Last name:</th><td>".$fist_last_name."</td></tr>

                <tr><th>School type:</th><td>".$school_type."</td></tr>

                <tr><th>Practice name:</th><td>".$practice_name."</td></tr>

                <tr><th>address1:</th><td>".$address1."</td></tr>

                <tr><th>address2:</th><td>".$address2."</td></tr>

                <tr><th>Zipcode:</th><td>".$zipcode."</td></tr>

                <tr><th>City:</th><td>".$city."</td></tr>

                <tr><th>Website:</th><td>".$website."</td></tr>

                <tr><th>Email:</th><td>".$email."</td></tr>

            </table>";

mail('emailaddress@domain.com','No Reply',$body,"From: noreply@domain.com");

?>

This is the JavaScript for the form validation:

/* Form validation */

$("form[name='apply']").submit(function(){
    var error = true;
    var text_fields = ["fist-last-name", "practice-name", "zipcode", "city", "website-address", "email"];
    $.each(text_fields,function(key,value){
        if(!$.trim($("input[name='"+value+"']").val()) == "") {
            $("input[name='"+value+"']").css({'border-color': '#ccc'});
        }
        else{
            $("input[name='"+value+"']").css({'border-color': 'red'});
            error = false;
        }
    });
    if($("form[name='apply'] select[name='select-school']").val() == "--select--") {
        $("form[name='apply'] select[name='select-school']").css({'border-color': 'red'});
        error = false;
    }
    else {
        $("form[name='apply'] select[name='select-school']").css({'border-color': '#ccc'});
    }
    var textarea_fields = ["address1", "address2"];
    $.each(textarea_fields,function(key,value){
        if(!$.trim($("form[name='apply'] textarea[name='"+value+"']").val()) == "" ) {
            $("form[name='apply'] textarea[name='"+value+"']").css({'border-color': '#ccc'});
        }
        else {
            $("form[name='apply'] textarea[name='"+value+"']").css({'border-color': 'red'});
            error = false;
        }
    });
    console.log(error);
    if(error == true) {
        $.post('mail.php',$("form[name='apply']").serialize(),function(data){
            console.log(data);
        });
    }
    return false;
});

$("form[name='apply'] input[type='text'], form[name='apply'] textarea").blur(function(){
    if($.trim($(this).val()) == ""){
        $(".error-message").text($(this).attr('title'));
        $(this).css({'border-color': 'red'});
    }
    else {
        $(this).css({'border-color': '#ccc'});
        $(".error-message").text('');
    }
});
$("form[name='apply'] input[type='text'], form[name='apply'] textarea").bind("keydown",function(){
    if($.trim($(this).val()) == ""){
        $(".error-message").text($(this).attr('title'));
        $(this).css({'border-color': 'red'});
    }
    else {
        $(this).css({'border-color': '#ccc'});
    }
});

The error occurs in this code:

$("form[name='apply']").submit(function(){
    var error = true;
    var text_fields = ["fist-last-name", "practice-name", "zipcode", "city", "website-address", "email"];
    $.each(text_fields,function(key,value){
        if(!$.trim($("input[name='"+value+"']").val()) == "") {
            $("input[name='"+value+"']").css({'border-color': '#ccc'});
        }
        else{
            $("input[name='"+value+"']").css({'border-color': 'red'});
            error = false;
        }
    });
    if($("form[name='apply'] select[name='select-school']").val() == "--select--") {
        $("form[name='apply'] select[name='select-school']").css({'border-color': 'red'});
        error = false;
    }
    else {
        $("form[name='apply'] select[name='select-school']").css({'border-color': '#ccc'});
    }
    var textarea_fields = ["address1", "address2"];
    $.each(textarea_fields,function(key,value){
        if(!$.trim($("form[name='apply'] textarea[name='"+value+"']").val()) == "" ) {
            $("form[name='apply'] textarea[name='"+value+"']").css({'border-color': '#ccc'});
        }
        else {
            $("form[name='apply'] textarea[name='"+value+"']").css({'border-color': 'red'});
            error = false;
        }
    });
    console.log(error);
    if(error == true) {
        $.post('mail.php',$("form[name='apply']").serialize(),function(data){
            console.log(data);
        });
    }
    return false;
}); 
  • 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-03T04:35:10+00:00Added an answer on June 3, 2026 at 4:35 am

    Your Javascript is stopping the form from submitting. When you return false in a form’s submit event, it prevents the form being submitted.

    I think you want to return the error variable which seems to be a boolean to indicate a validation error.

    Try:

    $("form[name='apply']").submit(function(){
    
        .... JS code ....
        return error;
    });
    

    Using that, if there are no validation errors, the form will submit. Also your error boolean is slightly misleading, it would be more logical if error is true then there is a validation error, but you have it reversed – won’t make any difference to the actual code execution, just a readability point.

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

Sidebar

Related Questions

I have... a dynamic populated select box several input boxes a submit button form
I have a image button thats acts as a form submit button: <a href=#
I have tried to replace the submit button of a form with an ajax
I have a checkbox with id terms and a submit button in my form
I have a form with a submit button. I have called a function on
I have a form with a css submit button. When a the submit button
I have a html form with no submit button. I want to submit that
I have a form, with a submit button: <% form_for(@personalentry) do |f| %> <%=
I have a form in an HTM page that, after pressing the submit button,
I have a form, and want to disable/enable its submit button depending on whether

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.