jQuery 1 3 with PHP 1st Edition Kae Verens instant download
jQuery 1 3 with PHP 1st Edition Kae Verens instant download
download
https://ebookname.com/product/jquery-1-3-with-php-1st-edition-
kae-verens/
https://ebookname.com/product/pro-php-and-jquery-1st-edition-
jason-lengstorf/
https://ebookname.com/product/pro-php-and-jquery-1st-edition-
jason-lengstorf-2/
https://ebookname.com/product/jquery-1-4-reference-guide-1st-
edition-karl-swedberg/
https://ebookname.com/product/computer-arithmetic-and-validity-
theory-implementation-and-applications-2ed-edition-ulrich-
kulisch/
Professional ASP NET 3 5 Security Membership and Role
Management with C and VB 1st Edition Bilal Haidar
https://ebookname.com/product/professional-asp-net-3-5-security-
membership-and-role-management-with-c-and-vb-1st-edition-bilal-
haidar/
https://ebookname.com/product/cox-2-inhibitor-research-1st-
edition-maynard-j-howardell/
https://ebookname.com/product/combinatorics-of-permutations-2nd-
edition-miklos-bona/
https://ebookname.com/product/common-legal-framework-for-
takeover-bids-in-europe-law-practitioner-series-volume-2-1st-
edition-van-gerven-dirk/
https://ebookname.com/product/the-belt-and-road-initiative-1st-
edition-keyopinion/
Israel s Occupation 2008 1st Edition Neve Gordon
https://ebookname.com/product/israel-s-occupation-2008-1st-
edition-neve-gordon/
jQuery 1.3 with PHP
Kae Verens
BIRMINGHAM - MUMBAI
This material is copyright and is licensed for the sole use by JEROME RAYMOND on 30th October 2009
125 Louis ST, , So. Hackensack, , 07606
jQuery 1.3 with PHP
All rights reserved. No part of this book may be reproduced, stored in a retrieval
system, or transmitted in any form or by any means, without the prior written
permission of the publisher, except in the case of brief quotations embedded in
critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of
the information presented. However, the information contained in this book is sold
without warranty, either express or implied. Neither the author, Packt Publishing,
nor its dealers or distributors will be held liable for any damages caused or alleged to
be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all the
companies and products mentioned in this book by the appropriate use of capitals.
However, Packt Publishing cannot guarantee the accuracy of this information.
ISBN 978-1-847196-98-9
www.packtpub.com
This material is copyright and is licensed for the sole use by JEROME RAYMOND on 30th October 2009
125 Louis ST, , So. Hackensack, , 07606
Credits
Acquisition Editor
Proofreader
Douglas Paterson
Chris Smith
Development Editor
Indexer
Darshana D. Shinde
Rekha Nair
Technical Editor
Production Coordinator
Ishita Dhabalia
Dolly Dasilva
Copy Editor
Cover Work
Sanchari Mukherjee
Dolly Dasilva
This material is copyright and is licensed for the sole use by JEROME RAYMOND on 30th October 2009
125 Louis ST, , So. Hackensack, , 07606
About the Author
Kae Verens lives in Monaghan, Ireland with his wife Bronwyn and their two kids
Jareth and Boann. He has been programming for twenty years, fifteen of which were
as a professional.
Kae started writing in JavaScript in the mid nineties, and started working on
the server-side languages a few years later. After writing CGI in C and Perl,
Kae switched to PHP in 2000, and has worked with it since then.
Kae is currently the secretary of the Irish PHP Users' Group, http://php.ie/,
is part-owner of the Irish web-development company Webworks.ie,
http://webworks.ie/, and is the author of popular web-based file-manager KFM,
http://kfm.verens.com/.
In his spare time, Kae plays the guitar, juggles, is learning to play the piano, and likes
to occasionally dust the skateboard off and mess around on it.
This material is copyright and is licensed for the sole use by JEROME RAYMOND on 30th October 2009
125 Louis ST, , So. Hackensack, , 07606
About the Reviewers
John K. Murphy is a graduate of the University of West Virginia and has been
wrapped up in computers and software development since the 1980s. When he is not
buried in a book or jumping out of an airplane, he works as an IT consultant.
John lives with his wife and two children in Pittsburgh, PA and is currently
obsessing about the Internet of Things.
This material is copyright and is licensed for the sole use by JEROME RAYMOND on 30th October 2009
125 Louis ST, , So. Hackensack, , 07606
This material is copyright and is licensed for the sole use by JEROME RAYMOND on 30th October 2009
125 Louis ST, , So. Hackensack, , 07606
Table of Contents
Preface 1
Chapter 1: Introduction and Overview 7
Expected developer skills 8
Differences between PHP and JavaScript 9
What is jQuery? 10
Why jQuery? 12
How does jQuery fit in with PHP? 13
How to work with the examples 14
Projects that use PHP and jQuery 16
WordPress 16
RoundCube 16
KFM 17
Drupal 18
Summary 18
Chapter 2: Quick Tricks 19
Dynamic select boxes 21
Client-side code 22
How it works 23
Server-side code 25
Quick deletes 26
Client-side code 27
Server-side code 30
Contextual help 31
Inline editing 36
Client-side code 36
Server-side code 41
Summary 41
This material is copyright and is licensed for the sole use by JEROME RAYMOND on 30th October 2009
125 Louis ST, , So. Hackensack, , 07606
Table of Contents
[ ii ]
This material is copyright and is licensed for the sole use by JEROME RAYMOND on 30th October 2009
125 Louis ST, , So. Hackensack, , 07606
Table of Contents
Auto-suggestion 87
Client-side code 88
Server-side code 89
Client-side code 90
Summary 91
Chapter 5: File Management 93
Security 93
Choosing a directory 95
Client-side code 95
Server-side code 97
Creating, renaming, and deleting
directories 100
Client-side code 100
Server-side code 104
Moving directories 105
Client-side code 105
Server-side code 108
File uploads 109
Client-side code 109
Server-side code 112
Renaming, deleting, and moving files 113
Client-side code 114
Server-side code 115
File downloads 116
Client-side code 116
Server-side code 117
Summary 118
Chapter 6: Calendars 119
Displaying the calendar 120
Creating an event 121
Client-side code 122
Server-side code 124
Loading events from the server 126
Client-side code 126
Server-side code 127
Moving and resizing events 128
Client-side code 128
Server-side code 129
[ iii ]
This material is copyright and is licensed for the sole use by JEROME RAYMOND on 30th October 2009
125 Louis ST, , So. Hackensack, , 07606
Table of Contents
[ iv ]
This material is copyright and is licensed for the sole use by JEROME RAYMOND on 30th October 2009
125 Louis ST, , So. Hackensack, , 07606
Table of Contents
[v]
This material is copyright and is licensed for the sole use by JEROME RAYMOND on 30th October 2009
125 Louis ST, , So. Hackensack, , 07606
Table of Contents
[ vi ]
This material is copyright and is licensed for the sole use by JEROME RAYMOND on 30th October 2009
125 Louis ST, , So. Hackensack, , 07606
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.
This material is copyright and is licensed for the sole use by JEROME RAYMOND on 30th October 2009
125 Louis ST, , So. Hackensack, , 07606
Preface
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 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 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.
[2]
This material is copyright and is licensed for the sole use by JEROME RAYMOND on 30th October 2009
125 Louis ST, , So. Hackensack, , 07606
Preface
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."
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"
[3]
This material is copyright and is licensed for the sole use by JEROME RAYMOND on 30th October 2009
125 Louis ST, , So. Hackensack, , 07606
Preface
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."
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.
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
suggest@packtpub.com.
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.
[4]
This material is copyright and is licensed for the sole use by JEROME RAYMOND on 30th October 2009
125 Louis ST, , So. Hackensack, , 07606
Preface
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.
We appreciate your help in protecting our authors, and our ability to bring you
valuable content.
Questions
You can contact us at questions@packtpub.com if you are having a problem with
any aspect of the book, and we will do our best to address it.
[5]
This material is copyright and is licensed for the sole use by JEROME RAYMOND on 30th October 2009
125 Louis ST, , So. Hackensack, , 07606
This material is copyright and is licensed for the sole use by JEROME RAYMOND on 30th October 2009
125 Louis ST, , So. Hackensack, , 07606
Introduction and Overview
Welcome!
The book is aimed at the PHP developers who usually don't write client-side
JavaScript, and would like an example-based introduction demonstrating a wide
variety of integrations between server-side and client-side code.
For years, JavaScript (the language that jQuery is written in) has been seen as a "toy"
language. However, the pervasiveness of Ajax has allowed it to break out of the
client side and become an essential tool for all serious web application developers.
Ajax is a tool used by client-side code to contact the server and get or send data
without needing to reload the entire page. It's used to update part of the page, or to
retrieve data for a JavaScript application, or to send data to the server. Ajax stands
for Asynchronous JavaScript And XML. However, the XML part is optional, and is
often replaced with plain text or another data format such as JSON (explained later
in this chapter).
This book will demonstrate how combining server-side PHP with client-side jQuery
can make JavaScript much more useful than just for "form checking".
It is assumed that you are a server-side web application developer who wants to take
a step into the client side and learn how to use JavaScript to make your applications
more efficient and exciting for the client.
To be very clear about it, this book is not about PHP, and it is not about jQuery—it is
about how to work with both PHP and jQuery. This book will teach you how to use
jQuery to create some really cool effects, but without you needing to have in-depth
knowledge of how jQuery works.
This material is copyright and is licensed for the sole use by JEROME RAYMOND on 30th October 2009
125 Louis ST, , So. Hackensack, , 07606
Introduction and Overview
With this book, we are more interested in providing some practical demonstrations
of PHP and jQuery with explanations, than in getting right down into the guts of
how JavaScript works and how it is different from PHP.
After reading this book, you will have seen and built a wide variety of example
applications. This would certainly be enough to immensely change how your current
PHP applications work.
Each chapter in this book is dedicated to a specific subject, and will usually involve
building a practical example, which you can use in your day-to-day work.
The book will not cover jQuery in depth—there are other books available that
are dedicated to it. This book is designed to help a PHP developer write some
immediately-useful client-side applications without needing weeks of study.
You need to understand how CSS selectors work. A CSS selector is the part of CSS that
goes to the left of the { character. jQuery selects elements by using CSS selectors, and
it's an extremely powerful way of choosing the elements that you wish to work on.
HTML is a must-have for every web developer. I think we can safely say that your
HTML skills are not lacking, especially because that's the environment that PHP is
usually working in.
Your PHP is expected to be good. You don't need to know everything about PHP,
but it is beneficial if you have already written a few full PHP projects yourself and
are comfortable with reading code and quickly understanding what it does.
You are not expected to be a good JavaScript writer. It will be useful, but the book is
written such that beginners should not have a problem understanding how it all fits
together. As a PHP developer, you will find that JavaScript is similar to PHP anyway,
so you should not have a problem reading the examples and understanding them.
[8]
This material is copyright and is licensed for the sole use by JEROME RAYMOND on 30th October 2009
125 Louis ST, , So. Hackensack, , 07606
Chapter 1
However, there are some interesting differences, which a PHP developer may
not have encountered before.
The most obvious example is Ajax: when you request information from the server,
it is bad design to have everything freeze while you're waiting for the data to return.
Instead, you write your script such that the data is sent, and you carry on with other
stuff. When the data returns, you handle it with another function.
This poses some interesting problems, such as race conditions, and how to pass
variables through to remind the script what it was supposed to be doing when the
Ajax request was fired.
A race condition occurs when one resource is accessed by two separate operations at
the same time and one of them changes the value. This is because computers always
do things one after the other; the change to the value will happen either before or
after the other operation. This uncertainty means that in asynchronous systems, such
as networks, care must be taken to make sure that things happen in the right order.
Race conditions are not a language-specific problem. They can happen anytime—say,
when you open a file, work on it, and close it, only to find that at the time you were
working on it, someone else came in and changed the name of the file. There are
many ways of solving these problems depending on the nature of the case. The most
common solution is to use a "lock", where if an operation is to write into a value, it
will first "lock" it (usually by setting a flag variable or creating a .lock file) before
it reads it, and then will "unlock" it (remove the file or unset the flag) after it has
completed its work.
When an asynchronous function is called and its return value is sent to a callback
function, that callback function must be reminded what the caller function was
doing, so that it can carry on with it. This can be done using closures. With closures,
the callback function is generated by the caller function, and has a copy of the caller's
environment, including what variables were set, among other things. Later in the
book, you will see some examples of this.
[9]
This material is copyright and is licensed for the sole use by JEROME RAYMOND on 30th October 2009
125 Louis ST, , So. Hackensack, , 07606
Introduction and Overview
What is jQuery?
jQuery is a JavaScript library that makes it easy to work with the Document Object
Model (DOM) of a website. jQuery is not a replacement for JavaScript. It is a
JavaScript library, which gives some extra functionality that is not available natively
in JavaScript itself.
jQuery also makes it very easy to add behaviors to elements. So, you can do things
like drag boxes around, have things happen when you hover a mouse cursor over
something, have scripts run when a select box is changed, and so on.
All of this can be accomplished in plain JavaScript if you feel the need to write it
yourself, but there is no point in re-inventing the wheel. If there is a tool available
that makes things easier for you, then you should not do it the hard way.
As an example, let's say that you want to get all of the <span> elements in a page that
are contained in an element with the testme class, and change their contents to the
word hi!. Here is the HTML of the example:
<html>
<head>
</head>
<body>
<h1 class="testme"><span>this will change</span></h1>
<p>this will not</p>
<p class="testme">this will also not</p>
<p class="testme"><span>this will change</span></p>
<a href="javascript:run_test()">do it</a>
</body>
</html>
[ 10 ]
This material is copyright and is licensed for the sole use by JEROME RAYMOND on 30th October 2009
125 Louis ST, , So. Hackensack, , 07606
Chapter 1
For the first test, here is how to do it in plain JavaScript. Place this code in the <head>
section of the previous HTML code.
<script>
function run_test(){
var i,j,els,els2;
els=document.getElementsByTagName('*');
for(i in els){
if(!/(^| )testme( |$)/.test(els[i].className))continue;
els2=els[i].getElementsByTagName('span');
for(j in els2){
els2[j].innerHTML='hi!';
}
}
}
</script>
It would be difficult to write this more compactly in pure JavaScript, but it's still
too complex to be maintainable. Really, if you saw that for the first time, would you
know straight away what it was trying to do? And, can you be sure that it will work
in all browsers?
With jQuery, you can write a much more readable piece of code. Replace the above
JavaScript with this:
<script src="../jquery.min.js"></script>
<script>
function run_test(){
$('.testme span').html('hi!');
}
</script>
[ 11 ]
This material is copyright and is licensed for the sole use by JEROME RAYMOND on 30th October 2009
125 Louis ST, , So. Hackensack, , 07606
Introduction and Overview
I know what you're thinking—where's the rest of it? Well, that's the whole thing. It
very concisely strips away the confusion and all that you end up with is a very clear
piece of code, which can be understood immediately. The problems of cross-browser
compatibility are also solved by using the jQuery library. You can be sure that the
new script will work as planned in all major browsers.
The example links to the jQuery library file, jquery.min.js, which you can download
from http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js.
Why jQuery?
There are many libraries and frameworks available for JavaScript, including
MooTools, Ext, Dojo, and Prototype. So, why use jQuery and not others? Here are
some of the reasons:
• jQuery has a huge number of plugins available for everything you could
imagine wanting to do online
• The information on the jQuery site is extremely well documented, with many
examples
• jQuery does not extend the elements that it works on, which means that
JavaScript such as 'for(i in el){...}' will still work
• jQuery's CSS selector engine, Sizzle, is arguably the most complete and the
quickest available
There are benefits and detractors to everything. So in the end, it's a matter of taste.
In my case, I was using MooTools before I turned to jQuery, but MooTools' habit of
extending every element it touches was interfering with my own code, so I had to
replace it.
I chose jQuery because the body of knowledge on it was very large (every second
article on JavaScript blogs appears to mention jQuery), it's impressively clean to
work with, and there are a massive number of plugins available.
Also, because jQuery is used in so many large projects (a few of which are mentioned
in the Projects that use PHP and jQuery section of this chapter). If you have ever
worked on any of those projects, you will find that the skills you learned on them are
transferable to other projects using jQuery.
[ 12 ]
This material is copyright and is licensed for the sole use by JEROME RAYMOND on 30th October 2009
125 Louis ST, , So. Hackensack, , 07606
Exploring the Variety of Random
Documents with Different Content
CHAPITRE IV
OU SANCHO PANZA RÉPOND AUX QUESTIONS ET ÉCLAIRCIT LES
SOUVENANCE
CETTE HISTOIRE
DULCINÉE
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookname.com