Feeds

Xajax and PHP: JavaScript without the pain

Automatic for the people

  • alert
  • submit to reddit

Choosing a cloud hosting partner with confidence

Send an Ajax request

We shall create an Xajax application to validate an input field in a form. The input form takes data to add a catalog entry to the database table Catalog. As a user begins to enter data in the input field Catalog Id, a XMLHttpRequest is sent to the server to validate the Catalog Id value added.

If the Catalog Id is not already defined in the database, a message "Catalog Id is Valid" gets displayed. If the Catalog Id is already defined in the database, a message "Catalog Id is not Valid" gets displayed, the Create Catalog button gets disabled and field values for the Catalog Id get added to the form.

The xajax PHP object performs the function of an intermediary between the client application and the server. In the Xajax application PHP script create a xajax object.

$xajax = new xajax();

The server side processing is performed by PHP functions. Create PHP functions validateCatalogId($formValues) and updateCatalog($formValues). Both these functions take a formValues parameter.

function validateCatalogId($formValues){}
function updateCatalog($formValues){}

Register the PHP functions with the xajax object using the registerFunction() method. The xajax object creates wrapper functions for the PHP functions that may be invoked from a PHP script or an input form event handler.

$xajax->registerFunction("validateCatalogId");
$xajax->registerFunction("updateCatalog");

Xajax generates asynchronous wrapper functions for the registered PHP functions. A wrapper function name uses the format phpfunction. Variable phpfunction is a server-side PHP function for which a wrapper function is to be defined. Xajax provides asynchronous form processing with the getFormValues(string formId) method. Using the getFormValues() method, an array of form field values may be submitted as an argument to a xajax asynchronous function.

Sections of a form may also be submitted instead of the complete form with the getFormValues(string formID ,boolean submitDisabledElements, string prefix]) function. The prefix parameter specifies that only form elements starting with that prefix should be submitted. Boolean parameter submitDisabledElementsspecifies if disabled elements are to be submitted. PHP functions validateCatalogId and updateCatalog define a parameter for an array of form field values. Before a XMLHttpRequestis initiated, specify the xajax object to handle requests with the processRequests() function.

$xajax->processRequests();

Providing a secure and efficient Helpdesk

More from The Register

next story
Preview redux: Microsoft ships new Windows 10 build with 7,000 changes
Latest bleeding-edge bits borrow Action Center from Windows Phone
Google opens Inbox – email for people too thick to handle email
Print this article out and give it to someone tech-y if you get stuck
Microsoft promises Windows 10 will mean two-factor auth for all
Sneak peek at security features Redmond's baking into new OS
UNIX greybeards threaten Debian fork over systemd plan
'Veteran Unix Admins' fear desktop emphasis is betraying open source
Entity Framework goes 'code first' as Microsoft pulls visual design tool
Visual Studio database diagramming's out the window
Google+ goes TITSUP. But WHO knew? How long? Anyone ... Hello ...
Wobbly Gmail, Contacts, Calendar on the other hand ...
DEATH by PowerPoint: Microsoft warns of 0-day attack hidden in slides
Might put out patch in update, might chuck it out sooner
Ubuntu 14.10 tries pulling a Steve Ballmer on cloudy offerings
Oi, Windows, centOS and openSUSE – behave, we're all friends here
prev story

Whitepapers

Choosing cloud Backup services
Demystify how you can address your data protection needs in your small- to medium-sized business and select the best online backup service to meet your needs.
Forging a new future with identity relationship management
Learn about ForgeRock's next generation IRM platform and how it is designed to empower CEOS's and enterprises to engage with consumers.
Security for virtualized datacentres
Legacy security solutions are inefficient due to the architectural differences between physical and virtual environments.
Reg Reader Research: SaaS based Email and Office Productivity Tools
Read this Reg reader report which provides advice and guidance for SMBs towards the use of SaaS based email and Office productivity tools.
Storage capacity and performance optimization at Mizuno USA
Mizuno USA turn to Tegile storage technology to solve both their SAN and backup issues.