Source for file index.php
Documentation is available at index.php
require_once 'HTML/AJAX/Helper.php';
$objAjaxHelper->serverUrl = './php/auto_server.php';
$objAjaxHelper->jsLibraries [] = 'haserializer';
$objAjaxHelper->stubs [] = 'login';
$strAjaxScript = $objAjaxHelper->setupAJAX ();
<title>Form validation (v2) with HTML_AJAX</title>
<?php echo $strAjaxScript ?>
<script type="text/javascript">
* Basic page initialization
// Set up the labels so they know the associated input elements
var arrLabels = document.getElementsByTagName("label");
for (var i=0; i < arrLabels.length; i++) {
var objTemp = arrLabels[i];
var strFor = objTemp.getAttribute('for');
// Set the ID of the label
objTemp.setAttribute('id', 'l' + strFor);
// Save the original class of the label (if any)
objTemp.setAttribute('classOrig', objTemp.getAttribute('class'));
// Set the focus on the first element
document.getElementById('username').focus();
* Sets the class of an element (build for this example)
function setElement(strElement, blnValidated) {
var objElem = document.getElementById('l' + strElement);
strClass = objElem.getAttribute('classOrig');
objElem.setAttribute('class', '' + strClass);
* Shows or hides an element
function toggleElement(strElement, blnVisible) {
var objStyle = document.getElementById(strElement).style;
objStyle.display = (blnVisible == 1) ? 'block' : 'none';
// Create object with values of the form
var objTemp = new Object();
objTemp['username'] = document.getElementById('username').value;
objTemp['password'] = document.getElementById('password').value;
objTemp['email'] = document.getElementById('email').value;
// Create a dummy callback so the loading box will appear...
var objCallback = { validate: function() {} };
// Send the object to the remote class
var objLogin = new login(objCallback);
objLogin.validate(objTemp);
<link rel="stylesheet" type="text/css" href="login.css" />
<!-- THE ERROR MESSAGES -->
<div id="messages" class="errorbox"></div>
<form action="" method="post" onSubmit="doLogin(); return false;">
<fieldset style="width: 500px;">
<legend>Enter your login details</legend>
<table width="400" border="0" cellspacing="0" cellpadding="2">
<td><label for="username">Username:</label></td>
<td><input type="text" name="username" id="username" size="40" tabindex="1"></td>
<td><label for="password">Password:</label></td>
<td><input type="text" name="password" id="password" size="40" tabindex="2"></td>
<td><label for="email">E-mail:</label></td>
<td><input type="text" name="email" id="email" size="40" tabindex="3"></td>
<td><input type="submit" value=" login "> <input type="reset" value=" reset "></td>
<div id="HTML_AJAX_LOADING" class="AjaxLoading">Please wait while loading</div>
<strong>This sample is an updated version of the original login sample</strong>:<br />
» It now uses the new HTML_AJAX_Action class.<br>
» The initialization of the labels and their input elements is done by Javascript to clean up the page (function: initPage()).<br>
<strong>Design notes</strong>:<br>
» The attribute "style.display" cannot be set from php code. Don't know why though. I created a wrapper function for it called "toggleElement" which does the trick. Funny enough when i execute thesame lines of script using ->insertScript nothing happens.<br>
» You have to add a dummy callback in order to show the loading progress bar.<br>
» Enter username "peter", password "gabriel" and any valid e-mail adress to see a messagebox.<br>
© under LGPL @ 21 nov 2005 by www.webunity.nl<br>
<script type="text/javascript">
if (document.getElementsByTagName) {
alert('This sample requires the DOM2 "getElementsByTagName" function.');
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
Documentation generated on Mon, 11 Mar 2019 14:38:55 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|