Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking that Mandatory Fields have been populated in a Form

Status
Not open for further replies.

MaKSiNG

Technical User
Dec 4, 2003
19
Hi All,

I have done a search but could not find any useful results.

I have used an XSLT to post the contents of a form to a Java Component for further processing.

The form contains fields which are mandatory for the user to fill in. My question is how do I do this mandatory field checking in the XSLT? Can someone point me to an example of how this is done?


Thx,
MaKS
 
you set up a javascript function to validate the form before posting, when submit is pressed...

XSL is used for translation... The only logic it contains is whether or not to display an element...



PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
You would validate your contents (in XML form) against an XSD file, which defines how the XML should look, including specifying a minimum length on an element. A simple example is this:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema"[/URL] elementFormDefault="qualified" attributeFormDefault="unqualified">
	<xs:element name="root">
		<xs:complexType>
			<xs:sequence>
				<xs:element name="FirstName">
					<xs:simpleType>
						<xs:restriction base="xs:string">
							<xs:minLength value="1"/>
							<xs:maxLength value="20"/>
						</xs:restriction>
					</xs:simpleType>
				</xs:element>
				<xs:element name="MiddleName" minOccurs="0">
					<xs:simpleType>
						<xs:restriction base="xs:string">
							<xs:minLength value="1"/>
							<xs:maxLength value="20"/>
						</xs:restriction>
					</xs:simpleType>
				</xs:element>
				<xs:element name="LastName">
					<xs:simpleType>
						<xs:restriction base="xs:string">
							<xs:minLength value="1"/>
							<xs:maxLength value="50"/>
						</xs:restriction>
					</xs:simpleType>
				</xs:element>
			</xs:sequence>
		</xs:complexType>
	</xs:element>
</xs:schema>
This says that FirstName is a string, with a minimum length of 1, and a maximum length of 20. This makes the element required, as well as requiring a value for the element.

MiddleName is an optional element (meaning it can be missing from the document). If it's supplied, it's minLength attribute says it must contain a value.

LastName is just like FirstName, but with a bigger content (50 characters).

Chip H.

____________________________________________________________________
Click here to learn Ways to help with Tsunami Relief
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top