initial commit master
initial commit

file:b/jquery.form.js (new)
--- /dev/null
+++ b/jquery.form.js
@@ -1,1 +1,171 @@
+/*

+ * jQuery validateForm Plugin

+ * version: 0.5

+ * @requires jQuery v1.3.2 or later

+ *

+ * @author  Razvan Stanga <razvi at razvi dot ro> http://www.razvi.ro

+ */

+

+(function($) {

+

+   $.fn.validateForm = function(settings) {

+   	

+	 	settings = $.extend({

+		   debug : false,

+		   iframe : false,

+		   hidecontainer : true,

+		   forgottxt : "Ai uitat sa completezi",

+		   executeOnSuccess : null,

+		   executeOnError : null

+		}, settings);

+

+    	return this.each(function() {

+	     	id = this.id;

+

+		    $("div#form"+id+"errors").hide ();

+			$("div#form"+id+"success").hide ();

+

+			/*

+			*   Check with ajax if available

+			*/

+			if ( settings.checklive != undefined ) {

+				if ( settings.checklive.length > 0 ) {

+					$(settings.checklive).each (function(i ,val) {

+						if ( val.et == undefined ) {

+							rnd = "";

+						} else {

+							rnd = val.et;

+						};

+						$("div#check-"+val.efield+rnd).append ('<span id="error_'+val.efield+rnd+'"></span>');

+						delayed = null;

+						$("input#"+val.efield).keyup (function(){

+    						clearTimeout(delayed);

+         					delayed = setTimeout(function() {

+								$.get (val.eurl+'?'+$("input#"+val.efield).attr('id')+'='+$("input#"+val.efield).attr('value'), {}, function(data){

+									if ( data.message != 0 ) {

+										$("span#error_"+val.efield+rnd).html (data.message);

+									} else {

+										$("span#error_"+val.efield+rnd).html ("");

+									};

+								}, 'json');

+         					}, 400);

+						});

+					});

+				};

+			};

+

+			/*

+			*   Set IFRAME, if multipart/form-data message

+			*/

+			if ( settings.iframe != false ) {

+				$("form#"+id).attr ("action", $("form#"+id).attr ("action")+"?ajax=true&iframe=true");

+				$("form#"+id).attr ("target", settings.iframe);

+			};

+			

+		    $("form#"+id).submit(function() {

+				id = this.id;

+		    	//$("div#form"+id+"errors").hide ();

+

+				vp = settings.params;

+

+				if ( vp.length > 0 ) {

+				    av = new FormValidator ( this.getAttribute("id") );

+				    $(vp).each (function(i ,val) {

+		                av.addElement (val.ename, val.etext, val.etype, val.echeck);

+				    });

+					error = av.validateIT ();

+				} else {

+					error = "";

+				};

+

+				if ( error ) {

+					error = "\n"+error;

+					$("div#form"+id+"errors").html("<strong>"+settings.forgottxt+"</strong><ul> "+ error.replace(/(\n)(.+)/g, "<li> $2<\/li>") + "<\/ul>").show (10, function(){

+                        // try to resize colorbox, it it exists

+                        try {

+							$.fn.colorbox.resize ();

+						}

+						catch (ex){}

+					});

+					return false;

+				};

+

+				var params = $(this).serialize ();

+

+				if ( settings.debug == true ) {

+                    $.post (this.getAttribute("action") + "?ajax=true", params, function(data) {

+						$("div#form"+id+"errors").show ();

+						$("div#form"+id+"errors").html (data);

+                    });

+                    return false;

+				};

+

+				if ( settings.iframe == false ) {

+					$.post (this.getAttribute("action") + "?ajax=true", params, function(data) {

+						

+						try {

+							success = data.success;

+							if (success.length > 0) {

+								$("div#form"+id+"success").html (success);

+	       					}

+       					}

+       					catch (ex) {}

+       					

+						errors = data.errors;

+						if (errors.length == 0) {

+							$("div#form"+id+"errors").hide ();

+							if ( settings.hidecontainer == true ) {

+								$("div#form"+id+"container").hide ();

+							}

+							

+							$("div#form"+id+"success").show (100, function (){

+								// try to resize colorbox, it it exists

+								try {

+									$.fn.colorbox.resize ();

+								}

+								catch (ex){}

+							});

+							

+							if ( data.load != undefined ) {

+								if ( data.load.length > 0 ) {

+									$(data.load).each (function(i ,val) {

+										$("div#"+val.div).load (val.url, function(){

+											if ( val.anchor != undefined ) {

+												goto = $("a#"+val.anchor).offset().top;

+												//alert ( val.anchor+' '+goto );

+												$("html,body").animate({ scrollTop: goto}, 1100, function() {

+													//window.location.hash = val.anchor

+												});

+											};

+										});

+									});

+								};

+							};

+							// execute function on success

+							if ( settings.executeOnSuccess != null ) {

+								settings.executeOnSuccess ();

+							}

+						} else {

+							errors = "\n"+errors;

+							$("div#form"+id+"errors").html ("<strong>Eroare<\/strong><ul>" + errors.replace(/(\n)(.+)/g, "<li> $2<\/li>") + "<\/ul>").show (10, function () {

+								// try to resize colorbox, it it exists

+								try {

+									$.fn.colorbox.resize ();

+								}

+								catch (ex){}

+							});

+							// execute function on error

+							if ( settings.executeOnError != null ) {

+								settings.executeOnError ();

+							}

+						};

+					}, 'json');

+					return false;

+				} else {

+					return true;

+				};

+			});

+    	})

+   };

+})(jQuery);

 

comments