Welcome Guest, Not a member yet? Register   Sign In
Form validation errors as a html list
#1

[eluser]Dirk Einecke[/eluser]
Hi,

I want to validate a form an show the error messages as a html list.

With set_error_delimiters a can set a delimiter,

Code:
$this->form_validation->set_error_delimiters('<li>', '</li>');

...but how can a check in the view that there is min 1 error to display the <ul>...</ul>?

Dirk
#2

[eluser]Flemming[/eluser]
I extended the form_validation library by placing a MY_Form_validation.php in my libraries folder and putting the error_string method in it, then modifiy it like this:

Code:
function error_string($prefix = '', $suffix = '', $container_open = '<ul class="error">', $container_close = '</ul>')

that way the opening and closing <ul></ul> only get echoed out IF there are some errors.

hope that helps?
#3

[eluser]Dirk Einecke[/eluser]
Hi,

I've found a other solution: In the controller I write all errors to an array and transmit it to the view...

Code in the controller:

Code:
$this->form_validation->set_error_delimiters('', '');
$arr_errors = (array) array(
  form_error('name'),
  form_error('email'),
  form_error('url'),
  form_error('text')
);


Dirk




Theme © iAndrew 2016 - Forum software by © MyBB