You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Richard In Public <ed...@blueyonder.co.uk> on 2003/03/07 01:48:03 UTC

XmlForm Validation Problem: Where Am I Going Wrong?

Hi

I think I'm pretty close to having things up and running with XMLForms.  I'm
having some problems with the validation though.  I'm trying to achieve
conditional validation:  I have two password fields and the second should
only be effected if a password has been entered in the first.  I don't want
to do this in the '/' content as I want any violations to be associated with
the second field.  I've tried everything that I can think of.  Here is one
of the attempts. Everything works except the validation of the second
password field.  No violations are reported when I fill in only the first
field.  Where am I going wrong?

My my dead lines are turning pale blue and gasping for breath.  Please
please help me!

Richard

------------------------ Validation Schema(tron) ---------------------
<?xml version="1.0" ?>
<schema ns="http://xml.apache.cocoon/xmlform"
xmlns="http://www.ascc.net/xml/schematron">
<title>Account Registration Schema</title>
<phase id="registration">
<p>For user identity information.</p>
<active pattern="reg"/>
</phase>
<pattern name="User Info Validation Pattern" id="reg">
<rule context="/emailAddress">
<assert test="contains( string(.),'@')">
Email format is invalid.
</assert>
</rule>
<rule context="/password">
<assert test="string-length(.) &gt; 7">
Password should be at least 8 characters.
</assert>
<assert test="string-length(.) &lt; 20">
Password should be less than 20 characters.
</assert>
</rule>
<rule context="/repeatedPassword">
<report test="(string-length(/password) &gt; 0) and (string-length(.) = 0)">
Please confirm your password.
</report>
</rule>
</pattern>
</schema>
----------------------------------------
XMLForm --------------------------------
<?xml version="1.0" ?>
<xf:form xmlns:xf="http://xml.apache.org/cocoon/xmlform/2002"
id="form-feedback" view="registration" action="new-account.xml"
xmlns:site="http://designedandmanaged.net/cocoon/site/1.0">
<error>
<xf:violations class="error"/>
</error>
<xf:textbox ref="/emailAddress">
<xf:caption>Email Address</xf:caption>
<xf:violations class="error" />
</xf:textbox>
<xf:password ref="/password">
<xf:caption>Password</xf:caption>
<xf:violations class="error" />
</xf:password>
<xf:password ref="/repeatedPassword">
<xf:caption>Password (Confirm)</xf:caption>
<xf:violations class="error" />
</xf:password>
<xf:textbox ref="/firstName">
<xf:caption>First Name</xf:caption>
<xf:violations class="error" />
</xf:textbox>
<xf:textbox ref="/lastName">
<xf:caption>Last Name</xf:caption>
<xf:violations class="error" />
</xf:textbox>
<xf:textbox ref="/phoneNumber">
<xf:caption>Phone Number</xf:caption>
<xf:violations class="error" />
</xf:textbox>
<xf:textbox ref="/address1">
<xf:caption>Line 1</xf:caption>
<xf:violations class="error" />
</xf:textbox>
<xf:textbox ref="/address2">
<xf:caption>Line 2</xf:caption>
<xf:violations class="error" />
</xf:textbox>
<xf:textbox ref="/address3">
<xf:caption>Line 3</xf:caption>
<xf:violations class="error" />
</xf:textbox>
<xf:textbox ref="/city">
<xf:caption>City</xf:caption>
<xf:violations class="error" />
</xf:textbox>
<xf:textbox ref="/postCode">
<xf:caption>Post Code</xf:caption>
<xf:violations class="error" />
</xf:textbox>
<xf:textbox ref="/countryID">
<xf:caption>Country</xf:caption>
<xf:violations class="error" />
</xf:textbox>
<xf:submit id="next" class="button">
<xf:caption>Create My Account</xf:caption>
<xf:hint>Go to next page</xf:hint>
</xf:submit>
</xf:form>


---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-users-help@xml.apache.org


Re: XmlForm Validation Problem: Where Am I Going Wrong?

Posted by Josema Alonso <jo...@simbiosystems.com>.
Hello,

I couldn't solve your problem but maybe I can give you more ideas...
In you rule:
<rule context="/repeatedPassword">
  <report test="(string-length(/password) &gt; 0) and (string-length(.) =
0)">
    Please confirm your password.
  </report>
</rule>

I would say you are setting the context to "/repeatedPassword", so
"/password" won't work. I think you should use "../password" in there. I
coudn't make this work either...ummm...but if I put any text in the
"/repeatedPassword" field, form does not pass validation and it does if I
leave it blank...weird...

Anyway, if you got it working you should consider writing a more consistent
rule for password confirming. Something like:
<rule context="/repeatedPassword">
  <assert test="string(.) = string(../password)">
    Please confirm your password.
  </assert>
</rule>

I can think of another way of making this, through some java code in the
perform() method (making validation programatically), but I hope it won't be
necessary cause I believe there must be a Schematron way of doing this. Hope
someone could help you (us) more :-)

Best,
Josema



----- Original Message -----
From: "Richard In Public" <ed...@blueyonder.co.uk>
To: <co...@xml.apache.org>
Sent: Friday, March 07, 2003 1:48 AM
Subject: XmlForm Validation Problem: Where Am I Going Wrong?


> Hi
>
> I think I'm pretty close to having things up and running with XMLForms.
I'm
> having some problems with the validation though.  I'm trying to achieve
> conditional validation:  I have two password fields and the second should
> only be effected if a password has been entered in the first.  I don't
want
> to do this in the '/' content as I want any violations to be associated
with
> the second field.  I've tried everything that I can think of.  Here is one
> of the attempts. Everything works except the validation of the second
> password field.  No violations are reported when I fill in only the first
> field.  Where am I going wrong?
>
> My my dead lines are turning pale blue and gasping for breath.  Please
> please help me!
>
> Richard
>
> ------------------------ Validation Schema(tron) ---------------------
> <?xml version="1.0" ?>
> <schema ns="http://xml.apache.cocoon/xmlform"
> xmlns="http://www.ascc.net/xml/schematron">
> <title>Account Registration Schema</title>
> <phase id="registration">
> <p>For user identity information.</p>
> <active pattern="reg"/>
> </phase>
> <pattern name="User Info Validation Pattern" id="reg">
> <rule context="/emailAddress">
> <assert test="contains( string(.),'@')">
> Email format is invalid.
> </assert>
> </rule>
> <rule context="/password">
> <assert test="string-length(.) &gt; 7">
> Password should be at least 8 characters.
> </assert>
> <assert test="string-length(.) &lt; 20">
> Password should be less than 20 characters.
> </assert>
> </rule>
> <rule context="/repeatedPassword">
> <report test="(string-length(/password) &gt; 0) and (string-length(.) =
0)">
> Please confirm your password.
> </report>
> </rule>
> </pattern>
> </schema>
> ----------------------------------------
> XMLForm --------------------------------
> <?xml version="1.0" ?>
> <xf:form xmlns:xf="http://xml.apache.org/cocoon/xmlform/2002"
> id="form-feedback" view="registration" action="new-account.xml"
> xmlns:site="http://designedandmanaged.net/cocoon/site/1.0">
> <error>
> <xf:violations class="error"/>
> </error>
> <xf:textbox ref="/emailAddress">
> <xf:caption>Email Address</xf:caption>
> <xf:violations class="error" />
> </xf:textbox>
> <xf:password ref="/password">
> <xf:caption>Password</xf:caption>
> <xf:violations class="error" />
> </xf:password>
> <xf:password ref="/repeatedPassword">
> <xf:caption>Password (Confirm)</xf:caption>
> <xf:violations class="error" />
> </xf:password>
> <xf:textbox ref="/firstName">
> <xf:caption>First Name</xf:caption>
> <xf:violations class="error" />
> </xf:textbox>
> <xf:textbox ref="/lastName">
> <xf:caption>Last Name</xf:caption>
> <xf:violations class="error" />
> </xf:textbox>
> <xf:textbox ref="/phoneNumber">
> <xf:caption>Phone Number</xf:caption>
> <xf:violations class="error" />
> </xf:textbox>
> <xf:textbox ref="/address1">
> <xf:caption>Line 1</xf:caption>
> <xf:violations class="error" />
> </xf:textbox>
> <xf:textbox ref="/address2">
> <xf:caption>Line 2</xf:caption>
> <xf:violations class="error" />
> </xf:textbox>
> <xf:textbox ref="/address3">
> <xf:caption>Line 3</xf:caption>
> <xf:violations class="error" />
> </xf:textbox>
> <xf:textbox ref="/city">
> <xf:caption>City</xf:caption>
> <xf:violations class="error" />
> </xf:textbox>
> <xf:textbox ref="/postCode">
> <xf:caption>Post Code</xf:caption>
> <xf:violations class="error" />
> </xf:textbox>
> <xf:textbox ref="/countryID">
> <xf:caption>Country</xf:caption>
> <xf:violations class="error" />
> </xf:textbox>
> <xf:submit id="next" class="button">
> <xf:caption>Create My Account</xf:caption>
> <xf:hint>Go to next page</xf:hint>
> </xf:submit>
> </xf:form>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: cocoon-users-help@xml.apache.org
>




---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-users-help@xml.apache.org