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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:42:56+00:00 2026-06-04T17:42:56+00:00

I’ve got a basic PHP contact form and have it process.php file that checks

  • 0

I’ve got a basic PHP contact form and have it process.php file that checks the content of the form. I have the form working correctly but i want to populate the contents of my returnstatus div with $errors without fully refreshing the page. I’m sure this is a simple task but i’m not sure how to go about it. Here is my code:

Contact Form

<?php session_start(); ?>

<html>
<head>
    <link rel="stylesheet" type="text/css" href="styles2.css" />
    <link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
</head>
    <body>

        <div id="contact-form" class="clearfix">
            <h1>Get In Touch!</h1>
            <img id="stamp" src="images/stamp.png" height="128" width="128" alt="Stamp"/>
            <h2>
                Please provide as much information as possible for me to help you with your enquiry
            </h2>
            <div id="returnstatus">

            </div>  
            <form method="post" action="process2.php">
                <label for="name">Name: <span class="required">*</span></label>  
                <input type="text" id="name" name="name" placeholder="Joe Bloggs" required="required" /> 

                <label for="email">Email Address: <span class="required">*</span></label>  
                <input type="email" id="email" name="email" placeholder="joebloggs@example.com" required="required" /> 

                <label for="message">Message: <span class="required">*</span></label>  
                <textarea id="message" name="message" placeholder="Your message must be greater than 20 characters" required="required" data-minlength="20"></textarea>  

                <input type="text" name="check" class="check" />
                <span id="loading"></span>  
                <input type="submit" value="Send!" id="submit-button" />  
                <p id="req-field-desc"><span class="required">*</span> indicates a required field</p> 
            </form>
        </div>

    </body>
<html>

process2.php

<?php   

$name       = check_input($_POST['name']);
$email      = check_input($_POST['email']);
$message    = check_input($_POST['message']);

$errors = "";
if (empty($name)){
    $errors .= "Please fill out the first name field <br/> ";
}
if (empty($email)){
    $errors .= "Please fill out the email field <br/> ";
} else {
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
    if(!preg_match($email_exp,$email)) {
        $errors .= 'The email address you entered does not appear to be valid<br />';
    }
}
if (strlen($message) < 21){
    $errors .= "Your message must be at least 20 characters";
}

if ($errors != "") {
    echo "<b>Message not sent</b><br/>";
    echo $errors;
} else {
    $errors = "<p>Thank you, $name, for your message.</p><p>I'll get back to you as soon as possible!</p>";
    echo $errors;
//send email if all is ok 
if ($_POST['check'] == '') {        //check to see if the hidden input entry is empty
    $headers = "From: {$email}" . "\r\n";  
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";  

    $emailbody = "<p>You have recieved a new message from the enquiries form on your website.</p> 
                                <p><strong>Name: </strong> {$name} </p> 
                                <p><strong>Email Address: </strong> {$email} </p> 
                                <p><strong>Message: </strong> {$message} </p>";
    mail("xxxxx@gmail.com","New Enquiry",$emailbody,$headers);  
    }
}  

function check_input($data)
{
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;
}

?>
  • 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-04T17:42:57+00:00Added an answer on June 4, 2026 at 5:42 pm

    The obvious answer is to send an AJAX request. Learn more at jQuery.post() or Request.HTML in MooTools. The handleSuccess methods below inject the HTML output from process2.php into returnstatus.

    mootools 1.4.5 Example

    (function(){
        var form = $$('#contact-form form')[0];
        var returnStatus = $('returnstatus');
        var handleSuccess = function(responseTree, responseElements, responseHTML, responseJavaScript) {
            returnStatus.set('html', responseHTML);
        };
        form.addEvent('submit', function() {
            new Request.HTML({
                url: form.get('action'), 
                onSuccess: handleSuccess
            }).post(form);
            return false;
        });
    })();
    

    jquery 1.7.2 Example

    (function(){
        var form = $('#contact-form form');
        var returnStatus = $('#returnstatus');
        var handleSuccess = function(data) {
            returnStatus.html(data);
        };
        form.submit(function() {
            $.post(form.attr('action'), form.serialize(), handleSuccess, 'html');
            return false;
        });
    })();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I've got a string that has curly quotes in it. I'd like to replace
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I have thousands of HTML files to process using Groovy/Java and I need to
I have a reasonable size flat file database of text documents mostly saved in

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.