Session field validation

basic functions and we:tags
Michael_S
Senior Member
Beiträge: 160
Registriert: Mi 4. Feb 2004, 02:39
Wohnort: London / UK
Kontaktdaten:

Session field validation

Beitragvon Michael_S » Do 25. Feb 2010, 18:59

Hi,

I would like to check multiple session fields to make sure data has been entered. I can do this on a individual basis with ifVarEmpty but I would like to display the message in the following way:

Please go back and fill out the required fields X1, X2, X3

How can I check multiple session fields at the same time to display the first part of my message "Please go back and fill out the required fields".

Thanks in advance,

Michael.
Production Area
London, UK
http://productionarea.com

MarS
Senior Member
Beiträge: 602
Registriert: Mo 2. Mai 2005, 11:30
Wohnort: Kiel
Kontaktdaten:

Re: Session field validation

Beitragvon MarS » Do 25. Feb 2010, 19:13

Something like this?

Code: Alles auswählen

<we:ifVarEmpty match="X1" type="sessionfield">
<we:ifVarEmpty match="X2" type="sessionfield">
<we:ifVarEmpty match="X3" type="sessionfield">
Please go back and fill out the required fields
</we:ifVarEmpty>
</we:ifVarEmpty>
</we:ifVarEmpty>

Michael_S
Senior Member
Beiträge: 160
Registriert: Mi 4. Feb 2004, 02:39
Wohnort: London / UK
Kontaktdaten:

Re: Session field validation

Beitragvon Michael_S » Fr 26. Feb 2010, 03:49

Hi Martin,

I've tried the nested ifVarEmpty tag before without success and have just tested the code on v6.0.0.7 and v6.0.0.8 using the following template. The individual ifVarEmpty queries work as expected but the nested ifVarEmpty tags fail to check multiple fields/values.

Have I made a simple mistake with the code or is there an issue with nested ifVarEmpty tags?

Kind regards,

Michael.

Code: Alles auswählen

<we:sessionStart />
<we:saveRegisteredUser />

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
	<we:title></we:title>
	<we:description/>
	<we:keywords/>
	<we:charset defined="UTF-8">UTF-8</we:charset>
	<style type="text/css">
		body { font-family: sans-serif; }
	</style>
</head>
<body>

<we:ifRegisteredUser>
<p><we:sessionLogout id="self">Logout</we:sessionLogout></p>

<!-- Nested error checking -->
<p>Nested <strong>ifVarEmpty</strong></p>
<we:ifVarEmpty match="Contact_FirstName" type="sessionfield">
<we:ifVarEmpty match="Contact_LastName" type="sessionfield">
<we:ifVarEmpty match="Contact_Email" type="sessionfield">

<p style="color: red;">Please fill in the required fields *</p>

</we:ifVarEmpty>
</we:ifVarEmpty>
</we:ifVarEmpty>
<!-- /Nested error checking -->

<!-- Error checking -->
<p><strong>ifVarEmpty</strong></p>
<p><we:ifVarEmpty match="Contact_FirstName" type="sessionfield"><span style="color: red;">First name</span><br /></we:ifVarEmpty>
<we:ifVarEmpty match="Contact_LastName" type="sessionfield"><span style="color: red;">Last name</span><br /></we:ifVarEmpty>
<we:ifVarEmpty match="Contact_Email" type="sessionfield"><span style="color: red;">Email</span></we:ifVarEmpty><br />
<we:ifVarEmpty match="Contact_Telephone" type="sessionfield">Telephone<br /></we:ifVarEmpty>
<we:ifVarEmpty match="Contact_Mobile" type="sessionfield">Mobile<br /></we:ifVarEmpty>
</p>
<!-- /Error checking -->

<we:form name="update" id="self" method="post" xml="true">
	<we:sessionField type="hidden" name="ID" />
	<p>First name <span style="color: red;">*</span><br />
	<we:sessionField type="textinput" name="Contact_FirstName" /></p>
	<p>Last name <span style="color: red;">*</span><br />
	<we:sessionField type="textinput" name="Contact_LastName" /></p>
	<p>Email <span style="color: red;">*</span><br />
	<we:sessionField type="textinput" name="Contact_Email" /></p>
	<p>Telephone<br />
	<we:sessionField type="textinput" name="Contact_Telephone" /></p>
	<p>Mobile<br />
	<we:sessionField type="textinput" name="Contact_Mobile" /></p>
	<p><input type="submit" value="Save" /></p>
</we:form>
</we:ifRegisteredUser>

<we:ifNotRegisteredUser>
<we:form name="login" id="self" method="post" xml="true">
	<we:ifLoginFailed>
	<p><strong>The login has failed. Please try again.</strong></p>
	</we:ifLoginFailed>
	<p><label for="Username">User name:</label><br />
	<we:sessionField name="Username" id="Username" type="textinput" xml="true" /></p>
	<p><label for="Password">Password:</label><br />
	<we:sessionField name="Password" id="Password" type="password" xml="true" /></p>
	<p><input type="submit" value="Login" /></p>
</we:form>
</we:ifNotRegisteredUser>

</body>
</html>
Production Area
London, UK
http://productionarea.com

we:willRockYou
Senior Member
Beiträge: 919
Registriert: Fr 22. Mai 2009, 21:40
Wohnort: Berlin
Kontaktdaten:

Re: Session field validation

Beitragvon we:willRockYou » Fr 26. Feb 2010, 08:57

Hi Michael,

the nested conditions will only work in it's whole. The content will only be displayed if all conditions are true, i.e. all 3 vars are empty.

If you want to test the vars individual, you need to define individual conditions.

Code: Alles auswählen

<we:ifVarEmpty match="Contact_FirstName" type="sessionfield">
   <p style="color: red;">Please fill in the required fields *</p>
</we:ifVarEmpty>
<we:ifVarEmpty match="Contact_LastName" type="sessionfield">
   <p style="color: red;">Please fill in the required fields *</p>
</we:ifVarEmpty>
<we:ifVarEmpty match="Contact_Email" type="sessionfield">
   <p style="color: red;">Please fill in the required fields *</p>
</we:ifVarEmpty>
Take a look and imagine what would happen if all 3 vars are empty. The red paragraph will be printed 3 times.

So that's not what you want either. So we have to define another variable. Something like this:

Code: Alles auswählen

<we:ifVarEmpty match="Contact_FirstName" type="sessionfield">
   <we:setVar to="global" nameto="validation_error" value="true" />
</we:ifVarEmpty>
<we:ifVarEmpty match="Contact_LastName" type="sessionfield">
   <we:setVar to="global" nameto="validation_error" value="true" />
</we:ifVarEmpty>
<we:ifVarEmpty match="Contact_Email" type="sessionfield">
   <we:setVar to="global" nameto="validation_error" value="true" />
</we:ifVarEmpty>
In case one of the conditions is true, we define the global variable "validation_error". Now you're able to test this variable in one central location and your red paragraph will only be displayed once.

Code: Alles auswählen

<we:ifVar name="validation_error" type="global" match="true">
   <p style="color: red;">Please fill in the required fields *</p>
</we:ifVar>
Kind regards,
Daniel

Michael_S
Senior Member
Beiträge: 160
Registriert: Mi 4. Feb 2004, 02:39
Wohnort: London / UK
Kontaktdaten:

Re: Session field validation

Beitragvon Michael_S » Fr 26. Feb 2010, 10:27

Hi Daniel,

Thanks that's been bugging me for years :-) I've tested it and everything works as it should, thanks for the quick reply. It would be really useful if we could name multiple match fields in one ifVarEmpty tag to reduce the coding, I will add this to the wish list.

Kind regards,

Michael.
Production Area
London, UK
http://productionarea.com


Zurück zu „Creating templates“

Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 6 Gäste