Book Image

PHP Ajax Cookbook

Book Image

PHP Ajax Cookbook

Overview of this book

Table of Contents (16 chapters)
PHP Ajax Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Building a PHP Ajax contact form with validation


Validation of the input box before submitting the form has become one of the very important Ajax functionalities. The user does not have to wait until the whole form gets back with some invalid input box messages and then try to refill it again. In this task, we will build a contact form with Ajax validation.

How to do it...

  1. Let's start with HTML:

    <body>
    <form id="contactForm" action="#" method="post">
      <h1>PHP Ajax Contact Form</h1>
      <div class="fieldRow">
        <label for="name">Your Name:</label>
        <input type="text" name="name" id="name" 
          class="required" />
      </div>
    
      <div class="fieldRow">
        <label for="email">Your e-mail:</label>
        <input type="text" name="email" id="email" 
          class="required email" />
      </div>
    
      <div class="fieldRow">
        <label for="url">Website:</label>
        <input type="text" name="url" id="url...