- From: Erik Bruchez <erik@bruchez.org>
- Date: Wed, 26 Oct 2005 06:03:56 +0200
- To: www-forms@w3.org
Daniel Swarbrick wrote: > 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 I don't think you would be able to do that with replace="none": you only get one of two events upon submission: xforms-submit-done in case of success, or xforms-submit-error in case of failure. No other useful information is associated with those events. > or replace:instance (and use an alternate instance with some > <xf:output>'s)? Yes, this is the way to handle it! See it this way: with <xforms:submission replace="instance" instance="my-result" .../>, you are actually calling an XML service implemented in PHP. That is, you are passing information to the service as XML (the submitted instance or subset thereof) and you are returning information from the service as XML as well. Here you are choosing to (mainly) return a list of errors. > 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 don't think so. But the result could look like this: Model: <xforms:bind ref="instance('my-result')" relevant="... XPath that determines whether there are errors"/> <xforms:bind ref="instance('other-instance')" relevant="... not(XPath that determines whether there are errors)"/> Controls: <xforms:group ref="instance('my-result')"> <xhtml:div> <xhtml:ul> <xforms:repeat nodeset="errors/error"> <xhtml:li> <xforms:output ref="."/> </xhtml:li> </xforms:repeat> </xhtml:ul> </xhtml:div> </xforms:group> <xforms:group ref="instance('other-instance')"> <xhtml:div> No errors! </xhtml:div> </xforms:group> Currently, XForms doesn't support conditional events, even though extensions have been suggested to do this. With such conditions, you could also use <xforms:switch> to implement a solution with something like this: Model: <xforms:submission ...> <xforms:action ev:event="xforms-submit-done"> <xforms:toggle exf:if="... XPath that determines whether there are errors" case="errors-case"/> <xforms:toggle exf:if="... not(XPath that determines whether there are errors)" case="no-errors-case"/> </xforms:action> </xforms:submission> Controls: <xforms:switch> <xforms:case id="errors-case"> <xhtml:div> <xhtml:ul> <xforms:repeat nodeset="errors/error"> <xhtml:li> <xforms:output ref="."/> </xhtml:li> </xforms:repeat> </xhtml:ul> </xhtml:div> </xforms:case> <xforms:case id="no-errors-case"> <xhtml:div> No errors! </xhtml:div> </xforms:case> </xforms:switch> But to do this, you actually need this "conditional events" extension in XForms. This is, BTW, something which is badly needed in the core of XForms or XML Events! > 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. I hope the above helps :-) -Erik
Received on Wednesday, 26 October 2005 04:03:56 UTC