Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying PHP Ajax Cookbook
  • Table Of Contents Toc
PHP Ajax Cookbook

PHP Ajax Cookbook

By : Milan Sedliak
4 (5)
close
close
PHP Ajax Cookbook

PHP Ajax Cookbook

4 (5)
By: Milan Sedliak

Overview of this book

This book contains a collection of recipes with step-by-step directions to build SEO-friendly websites using standard Ajax tools. Each recipe contains behind-the-scene explanations to PHP Ajax questions. This book is an ideal resource for people who like to add Ajax features to websites and who prefer standards and best practices for building SEO-friendly websites. As the book covers advanced topics, readers need to be aware of basic PHP, JavaScript and XML features.
Table of Contents (16 chapters)
close
close
PHP Ajax Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
1
Index

Validating a form using Ajax


The main idea of Ajax is to get data from the server in real time without reloading the whole page. In this task we will build a simple form with validation using Ajax.

Getting ready

As a JavaScript library is used in this task, we will choose jQuery. We will download (if we haven't done it already) and include it in our page. We need to prepare some dummy PHP code to retrieve the validation results. In this example, let's name it inputValidation.php. We are just checking for the existence of a param variable. If this variable is introduced in the GET request, we confirm the validation and send an OK status back to the page:

<?php
$result = array();
if(isset($_GET["param"])){
  $result["status"] = "OK";
  $result["message"] = "Input is valid!";
} else {
  $result["status"] = "ERROR";
  $result["message"] = "Input IS NOT valid!";
}

echo json_encode($result);
?>

How to do it...

  1. Let's start with basic HTML structure. We will define a form with three input boxes...

CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
PHP Ajax Cookbook
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon