You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Paul Pattison <pa...@76design.com> on 2002/05/15 02:59:15 UTC
Form validation
I was looking at the Form Validation sample today and I found that there was
a little more code in the xsp page then I would like.
I'm trying to find a way to get the if-else if statements out of the page
and put them into the action instead. Here's what I came up with. I tried
to put the needed error message into the descriptor file.
I haven't tried writing the action yet, I thought I'd see what people
thought of this way of doing it. I've included code below. Is it possible
this way? Is it a good way of doing it?
Any comments greatly appreciated,
Paul
Here's what my descriptor file would look like:
<?xml version="1.0"?>
<root>
<parameter name="persons" type="long" default="4" nullable="yes">
<constraint name="min" value="2">
<err-msg>The smallest available car seats 2.</err-msg>
</constraint>
<constraint name="max" value="7">
<err-msg>The largest available car seats 7.</err-msg>
</constraint>
</parameter>
<parameter name="deposit" type="double">
<constraint name="min" value="10.0">
<err-msg>The deposit has to be at least EUR 10.00.</err-msg>
</constraint>
<constraint name="max" value="999.99">
<err-msg>The deposit has to be at most EUR 999.99.</err-msg>
</constraint>
</parameter>
<constraint-set name="car-reservation">
<validate name="persons"/>
<validate name="deposit"/>
</constraint-set>
</root>
Here's a snippet from the xsp file:
<xsp:page>
...
How many persons should the car seat?
<input type="text" name="persons" size="2">
<xsp:attribute name="value"><xsp-request:get-parameter name="persons"
default=""/></xsp:attribute>
</input>
<error>
<xsp-request:get-parameter name="persons-err"/>
</error>
...
</xsp:page>
---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>
To unsubscribe, e-mail: <co...@xml.apache.org>
For additional commands, e-mail: <co...@xml.apache.org>
Re: Form validation
Posted by Christian Haul <ha...@dvs1.informatik.tu-darmstadt.de>.
There is new foms support underway for cocoon using an XForms related
syntax. FormvalidatorAction will stay but large additions might not be
worthwile....
On 14.May.2002 -- 08:59 PM, Paul Pattison wrote:
> I'm trying to find a way to get the if-else if statements out of the page
> and put them into the action instead. Here's what I came up with. I tried
> to put the needed error message into the descriptor file.
The formval logicsheet features "on-XYZ" tags, which are evaluated
only, if condition XYZ is true.
> I haven't tried writing the action yet, I thought I'd see what people
> thought of this way of doing it. I've included code below. Is it possible
> this way? Is it a good way of doing it?
Internationalization would be more difficult to achieve this way.
Besides, I like to use the formval logicsheet as a building block for
my own custom logicsheet. E.g. I like red stars behind a field that is
required or does not conform with the expected format. For this I use
<dvs-form:input type="checkbox" name="os" value="macosX"/> MacOS X<br/>
and
<xsl:template match="dvs-form:input">
<input>
<xsl:for-each select="@*">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:for-each>
<xsp:attribute name="value">
<xsp-request:get-parameter>
<xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute>
<xsl:attribute name="default"><xsl:value-of select="@default"/></xsl:attribute>
</xsp-request:get-parameter>
</xsp:attribute>
</input>
<xsp-formval:on-error>
<xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute>
<font color="red">*</font>
</xsp-formval:on-error>
</xsl:template>
HTH
Chris.
--
C h r i s t i a n H a u l
haul@informatik.tu-darmstadt.de
fingerprint: 99B0 1D9D 7919 644A 4837 7D73 FEF9 6856 335A 9E08
---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>
To unsubscribe, e-mail: <co...@xml.apache.org>
For additional commands, e-mail: <co...@xml.apache.org>