Aftervalidate - Get Form Data

I am using afterValidate option in CActiveForm. I have a JS function:


function validateListing(form, data, hasError)

In my form I have a checkbox array: $_POST[‘Listing’][‘selections’]

How can I access this and pass the data in to an AJAX call? I have tried:


var selections = form.selections;


$.ajax({

	url: base_url + '/account/listings/getcategorytags/',

	type: 'post',

	data: {

		selections : selections

	},

	dataType: 'json',

	success: function(result){

		$('.tags').html(result.view);

	}

});

Does not work. Can anyone help?

I managed to get it to work by doing the following:


var selections = {

	'selections[]' : []

};

			

$('#Listing_selections input:checked').each(function() {

	selections['selections[]'].push($(this).val());

});

			

$.ajax({

	url: base_url + '/account/listings/getcategorytags/',

	type: 'post',

	data: selections,

	dataType: 'json',

	success: function(result){

		$('.tags').html(result.view);

	}

});

But does anyone know how I can reference ‘selections’ post array using the built-in ‘form’ parameter of ‘afterValidate’ function?

Anybody got any idea about this?

We can get the checkBoxList value in afterValidate method in the following way.




'clientOptions'=>array(

		'validateOnSubmit'=>true,

		'afterValidate'=>new CJavaScriptExpression('function(f,d,e){

			var settings=$(f).data("settings");

			var attributes=settings.attributes;

			$.each(attributes,function(index,item){

					if(item.name==="selections")

						console.log(item.value);

				});

			

			return true;}')

		)




Hi seenivasan,

Thanks - that works.

I was just wondering where did you get this info from? Is it documented anywhere - for example this part:


var settings=$(f).data("settings");

var attributes=settings.attributes;

Hi seenivasan,

var settings=$(f).data("settings");

var attributes=settings.attributes;

can i add custom validation message for client side validation? thanks in advance.