Changeset

4489:e68bc6f35106

util.dataforms: Fix form verification
author Florian Zeitz <florob@babelmonkeys.de>
date Fri, 02 Dec 2011 19:24:54 +0100
parents 4477:b34eee3712c3
children 4490:b672fe29184b
files util/dataforms.lua
diffstat 1 files changed, 13 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/util/dataforms.lua	Mon Dec 12 14:53:12 2011 +0500
+++ b/util/dataforms.lua	Fri Dec 02 19:24:54 2011 +0100
@@ -120,12 +120,18 @@
 			end
 		end
 
-		local reader = field_readers[field.type];
-		local verifier = field.verifier or field_verifiers[field.type];
-		if reader then
-			data[field.name] = reader(tag);
-			if verifier then
-				errors[field.name] = verifier(data[field.name], tag, field.required);
+		if not tag then
+			if field.required then
+				errors[field.name] = "Required value missing";
+			end
+		else
+			local reader = field_readers[field.type];
+			local verifier = field.verifier or field_verifiers[field.type];
+			if reader then
+				data[field.name] = reader(tag);
+				if verifier then
+					errors[field.name] = verifier(data[field.name], tag, field.required);
+				end
 			end
 		end
 	end
@@ -161,7 +167,7 @@
 
 field_verifiers["jid-single"] =
 	function (data, field_tag, required)
-		if #data == 0 and required then
+		if ((not data) or (#data == 0)) and required then
 			return "Required value missing";
 		end
 		if not jid_prep(data) then