Source for file index.php
Documentation is available at index.php
* A simple guestbook with the goal of not a line of javascript :)
* @author Elizabeth Smith <auroraeosrose@gmail.com>
* @copyright 2005 Elizabeth Smith
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @version Release: 0.5.4
* @link http://pear.php.net/package/HTML_AJAX
//require the helper class - it will take care of everything else
require_once 'HTML/AJAX/Helper.php';
//since we're not REALLY using a backend like a database, use sessions to store data
//set up HTML_AJAX_Helper
//tell it what url to use for the server
$ajaxHelper->serverUrl = 'auto_server.php';
//add haserializer to set
$ajaxHelper->jsLibraries [] = 'haserializer';
// Open tags problem... I know ugly.
$ajaxHelper->stubs [] = 'guestbook';
print '<?xml version="1.0" encoding="utf-8"?>';
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<title>My Guestbook</title>
// output a javascript neded to setup HTML_AJAX
echo $ajaxHelper->setupAJAX ();
<script type="text/javascript">
HTML_AJAX.onError = function(e) { alert(HTML_AJAX_Util.quickPrint(e)); }
#guestbookForm, #guestbookList {
background-color: #D5BFFF;
border: 4px double #FFCC00;
background-color: #FFF2BF;
border: 4px double #330099;
margin: 0 0.5em 0.5em 0.5em;
background-color: #B38F00;
border: 1px solid #AA80FF;
input:focus, textarea:focus {
background-color: #D5BFFF;
border: 1px solid #B38F00;
margin: 0 0.5em 0.5em 0.5em;
background-color: #B38F00;
border: 1px solid #AA80FF;
background-color: #330099;
border: 3px double #FFE680;
<?php //eventually ajax_helper should set this up for you, it's not done yet?>
<script type="text/javascript">
function sendguestbook(form) {
var remoteguestbook = new guestbook();
var payload = new Object();
for(var i = 0; i < form.elements.length; i++) {
if (form.elements[i].name) {
payload[form.elements[i].name] = form.elements[i].value;
remoteguestbook.newEntry(payload);
function clearguestbook() {
var remoteguestbook = new guestbook();
remoteguestbook.clearGuestbook();
function deleteentry(id) {
var remoteguestbook = new guestbook();
remoteguestbook.deleteEntry(id);
var remoteguestbook = new guestbook();
remoteguestbook.editEntry(id);
function updateselect(id) {
var remoteguestbook = new guestbook();
remoteguestbook.updateSelect(id);
<h2>Welcome to the Guestbook</h2>
if (isset ($_SESSION['entries'])) {
foreach($_SESSION['entries'] as $key => $data) {
echo '<div class="entry" id="entry'. $key. '">'
. '<h3><a href="mailto:'. $data->email. '">'. $data->name. '</a></h3>';
if(!empty ($data->website ))
echo '<a href="http://'. $data->website. '">'. $data->website. '</a><br />';
echo '<p>'. $data->comments. '</p>'
. '<div class="small">Posted: '. $data->date. ' | '
. '<a href="#" onclick="editentry('. $key. ');">Edit</a> | '
. '<a href="#" onclick="deleteentry('. $key. ');">Delete</a></div>'
<div><a href="#" onclick="clearguestbook(this);">Clear Guestbook</a></div>
<form id="guestbookForm" action="index.php" method="post" onsubmit="sendguestbook(this); return false;">
<legend>Leave Your Comments</legend>
<label for="name">Name: </label><input name="name" id="name" />
<label for="email">Email: </label><input name="email" id="email" />
<label for="website">Website: </label><input name="website" id="website" />
<label for="comments">Comments: </label><textarea name="comments" id="comments"></textarea>
<br style="clear: both" />
<input type="submit" id="submit" name="submit" value="Add Comments" />
<p>Fill a select item with a list of options - tests the HTML_AJAX_Action::replaceNode and HTML_AJAX_Action::createNode methods</p>
<form id="testing" action="index.php" method="post" onsubmit="return false;">
<a href="#" onclick="updateselect('replaceme');">Gimme some options</a>
<option name="dog" id="dog">Dog</option>
Documentation generated on Fri, 04 Apr 2008 18:30:17 -0400 by phpDocumentor 1.4.0. PEAR Logo Copyright © PHP Group 2004.
|