W3C home > Mailing lists > Public > www-forms@w3.org > October 2005

Re: AJAX vs. Xforms

From: Daniel Swarbrick <daniel@pressure.net.nz>
Date: Wed, 26 Oct 2005 15:06:03 +1300
Message-ID: <435EE48B.3000204@pressure.net.nz>
To: www-forms@w3.org

I'm currently trying to migrate an AJAX app to XForms, and when I saw 
this thread, I thought it would be a good opportunity to ask for some 
help and guidance.

I've been keeping the forms in my current AJAX app deliberately simple, 
as I didn't really want to invest too much time reinventing the wheel 
doing form serialization in AJAX. In addition to this, I use AJAX to 
pre-populate the form by querying the web server for a simple XML 
document. I don't use XSL or XPath or any other fancy stuff (that I'm 
still learning) - I'm using Javascript getElementsByTagName on the 
XMLHttpRequest.responseXML to "walk" the XML tree - I know this can be 
done better using a proper XML object and manipulating the DOM, but this 
is half way to an XForms processor. Some of the forms include combo 
boxes that are also populated via an AJAX request (again, Javascript 
inserting options in a <select> by reading the returned simple XML 
document). This also involves a bit of script to set the value of the 
combo box to the currently selected value in the current record.

Upon submit, the server does field type/range/regex validation (in PHP), 
as well as attempt an SQL INSERT. If the RDBMS returns a primary key 
violation, or if PHP finds field validation errors, the web server 
returns a formatted XML document with nodes indicating the error-causing 
field, and an error message for each.

Sound like a good case for XForms? You betcha! I'm pretty sure I can do 
most of it with the knowledge I already have, but the DB primary key 
check is stumping me.

How can I get XForms to display these XML-formatted errors returned by 
the server? Should I use a replace:none and try to handle it with an 
event, or replace:instance (and use an alternate instance with some 
<xf:output>'s)? Based on whether the DB insert is a success or not, my 
page should display a differently-styled response - big loud yellow DIV 
with bulleted (<ul>) errors if it fails, or nice calm pale blue "Saved 
OK" if it succeeds. Is that a case for XSLT?

I've looked around a lot for some suitable examples, but everything 
seems to focus on the "server-side validation is now unnecessary" theme. 
Well, I beg to differ. No matter how smart XForms gets with client-side 
validation, the server still has to attempt the DB insert before it 
knows if it's got a duplicate key violation. Trapping this response from 
the server is the bit I need help with.

Thanks in advance (and sorry for the long email!)
Received on Wednesday, 26 October 2005 02:06:10 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Saturday, 10 March 2012 06:22:02 GMT