Book Image

jQuery 1.3 with PHP

Book Image

jQuery 1.3 with PHP

Overview of this book

To make PHP applications that respond quickly, avoid unnecessary page reloads, and provide great user interfaces, often requires complex JavaScript techniques and even then, if you get that far, they might not even work across different browsers! With jQuery, you can use one of the most popular JavaScript libraries, forget about cross-browser issues, and simplify the creation of very powerful and responsive interfaces ñ all with the minimum of code. This is the first book in the market that will ease the server-side PHP coder into the client-side world of the popular jQuery JavaScript library. This book will show you how to use jQuery to enhance your PHP applications, with many examples using jQuery's user interface library jQuery UI, and other examples using popular jQuery plugins. It will help you to add exciting user interface features to liven up your PHP applications without having to become a master of client-side JavaScript. This book will teach you how to use jQuery to create some really stunning effects, but without you needing to have in-depth knowledge of how jQuery works. It provides you with everything you need to build practical user interfaces for everything from graphics manipulation to drag-and-drop to data searching, and much more. The book also provides practical demonstrations of PHP and jQuery and explains those examples, rather than starting from how JavaScript works and how it is different from PHP. By the end of this book, you should be able to take any PHP application you have written, and transform it into a responsive, user-friendly interface, with capabilities you would not have dreamed of being able to achieve, all in just a few lines of JavaScript.
Table of Contents (16 chapters)
jQuery 1.3 with PHP
Credits
About the Author
About the Reviewers
Preface
Index

Preface

Creating PHP applications that respond quickly, avoid unnecessary page reloads, and provide great user interfaces, often requires complex JavaScript techniques. Even then, if you get that far, the results might not work across different browsers! With jQuery, you can use one of the most popular JavaScript libraries, forget about cross-browser issues, and simplify the creation of very powerful and responsive interfaces—all with the minimum of code.

This is the first book in the market that will ease the server-side PHP coder into the client-side world of the popular jQuery JavaScript library.

This book will show you how to use jQuery to enhance your PHP applications, with many examples using jQuery's user interface library jQuery UI, and other examples using popular jQuery plugins. It will help you to add exciting user interface features to liven up your PHP applications without having to become a master of client-side JavaScript.

This book will teach you how to use jQuery to create some really stunning effects, but without you needing to have in-depth knowledge of how jQuery works. It provides you with everything you need to build practical user interfaces, for everything from graphics manipulation and drag-and-drop to data searching, and much more. The book also provides practical demonstrations of PHP and jQuery and explains these examples, rather than starting from how JavaScript works and how it is different from PHP.

By the end of this book, you should be able to take any PHP application you have written, and transform it into a responsive, user-friendly interface, with capabilities you would not have dreamed of being able to achieve, all in just a few lines of JavaScript.

What this book covers

Chapter 1, Introduction and Overview, introduces you to what jQuery is, why you would want to use it, and why is it useful to combine it with PHP. Also, it gives a list of projects illustrating uses for combining PHP and jQuery.

Chapter 2, Quick Tricks, looks at a few quick examples on how to interface PHP and jQuery and a few tricks, which demonstrate how to relieve the most obvious resource wastes on the server.

Chapter 3, Tabs and Accordions, walks through the creation of tabs and accordions using the jQuery UI project, managing tabs and accordions using a rich text editor and a bit of PHP, and using Ajax to populate your accordion and tab panels.

Chapter 4, Forms and Form Validation, explores form validation using jQuery and PHP and how to use the same PHP configuration to validate on both sides—the server and the client side. It also covers examples on optimization of large select boxes and building auto-suggest fields.

Chapter 5, File Management, teaches you to manage almost everything—creating, uploading, editing, moving, downloading, and deleting files and directories.

Chapter 6, Calendars, builds a weekly calendar for you, which has events that can be created, edited, moved around, and deleted. It also takes care of recurring events.

Chapter 7, Image Manipulation, discusses methods for manipulating images with jQuery and PHP, along with some ways to make the changes non-destructive, so that multiple manipulations, such as select, rotate, resize, and crop, can be made on the same image.

Chapter 8, Drag and Drop, demonstrates a few uses of drag and drop, including sorting lists, dragging between lists, and hierarchical sorting, which can be used to improve the usability of your content management system.

Chapter 9, Data Tables, builds a very large data table and discusses how to navigate, sort, search, paginate, and search it using jQuery and Ajax.

Chapter 10, Optimization, shows the ways to optimize jQuery and various other elements of the web development environment.

What you need for this book

To try out the examples in this book, all you need is a test server; we recommend using PHP 5.2 or up. You will also need to download the jQuery library from http://docs.jquery.com/Downloading_jQuery.

Who this book is for

This book is for PHP application developers who want to improve their user interfaces through jQuery's capabilities and responsiveness. Whether you are familiar with jQuery or have only dabbled a little with JavaScript, this book will provide you with numerous practical examples on how to improve your application.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text are shown as follows: "The URL string we're working with includes a number of sSearch parameters."

A block of code is set as follows:

<?php 
  $dir='.'; // directory containing the scripts 
  $d=0; 
  foreach (new DirectoryIterator($dir) as $file) { 
    $d+=$file->getMTime(); 
  } 
?> 

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

$.getJSON('./calendar.php?action=get_event&id='+calEvent.id,function(eventdata){ 
  var controls='<a href="javascript:calendar_delete_entry('+eventdata.id+');">'+'[delete]</a>';
    if(+eventdata.recurring)controls+='<br />'+'<a href="javascript:calendar_delete_recurrences('+eventdata.id+')">'+' [stop recurring]</a>';
      $('<div id="calendar_edit_entry_form"

Any command-line input or output is written as follows:

yum install php-pecl-imagick

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "When you click on this ? icon, smaller help icons will be shown next to all the elements in the page."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an email to , and mention the book title via the subject of your message.

If there is a book that you need and would like to see us publish, please send us a note in the SUGGEST A TITLE form on www.packtpub.com or email .

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Tip

Downloading the example code for the book

Visit http://www.packtpub.com/files/code/6989_Code.zip to directly download the example code.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration, and help us to improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the let us know link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata added to any list of existing errata. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or web site name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.