[eluser]bretticus[/eluser]
Quote:is there anyway to set the paragraph class as the field name?
I strongly doubt it, but I'm not sure why you need to do this anyway (I'll explain further below.)
Also, you are setting the wrapper for error messages with:
Code:
$this->form_validation->set_error_delimiters('<p class=""/>', '</div>');
But you have a complete paragraph tag and then a closing div??? Did you leave the opening div out by chance?
Either way, I think this is unnecessary. I assume you mean to get the errors via AJAX from the output of validation_errors(). There is a better way I think. For example, I just return the entire error array after calling run() from the form_validation object. It's undocumented but there for the picking. Here's some code from one of my projects:
Code:
if ($this->form_validation->run() === FALSE) {
if ( IS_AJAX ) {
json_headers(); //optional json headers via custom helper (don't let this distract you.)
$response = $this->form_validation->_error_array;
echo json_encode($response);
}
}
$this->form_validation->_error_array is an associative array with the field names as keys and, as the values, error messages. Perfect! I return that as JSON so I can use the variables as native javascript variables. For example, using jquery's post method:
Code:
$.post('controller/method', {param1: some_value}, function(data) {
$.each(data, function (field,error) {
$('#'+field).css('background-color', 'red');
$('<p>'+error+'</p>').insertAfter('#'+field);
});
}, 'json');