Welcome Guest, Not a member yet? Register   Sign In
simple validation question
#1

[eluser]smickiedoo[/eluser]
Is there any way to know true or false if a form has failed with error messages?

I have a long registration form and I'm using individual error messages under each field. The problem is that when the form fails the user has to scroll down to see the individual error messages, and Id like to put something at the top that reads like "please verify that you've completed all required fields".

I tried the echo $this->validation->error_string; but it doesn't return anything. Perhaps because I'm using individual error messages?

silly problem.

thanks for any help
#2

[eluser]Chris Newton[/eluser]
As far as I know the error_string is not available in CI 1.7, so if you are using the new form validation class ($this->load->library('form_validation')Wink, you need to display the entire string like so:
&lt;?php echo validation_errors('<div class="error">', '</div>'); ?&gt;


If you are using an older version, I know that you can use both individual errors and error_string.
Here's the URL for the old validation library:
http://ellislab.com/codeigniter/user-gui...ation.html
#3

[eluser]smickiedoo[/eluser]
Shucks, still not showing anything. I'm using CI 1.7 and all of the other error fields are showing errors.
#4

[eluser]xwero[/eluser]
In the controller you can add a boolean variable has_errors that is switched to true when the validation is false.
Code:
$data['has_errors'] = FALSE;
if( ! $this->form_validation->run() )
{
    $data['has_errors'] = TRUE;
}
$this->load->view('form',data);
And in the view you can add
Code:
&lt;?php if($has_errors) echo lang('has_errors') ?&gt;
That should do the trick.
#5

[eluser]Colin Williams[/eluser]
Really!? Is $this->validation->error_string no longer a property? I think it still is. Upgraded my 1.6.3 to 1.7, which does a lot of if ($this->validation->error_string){} and haven't noticed any changed functionality...
#6

[eluser]xwero[/eluser]
error_string is still a property, which should be removed, but it is not filled. If you open the Form_validation library file and you do a search for error_string you get two results: the adding of the class variable and the new error_string function.

You get a filled error_string because you still use the old validation library.
#7

[eluser]Colin Williams[/eluser]
Quote:You get a filled error_string because you still use the old validation library.

Bah! Such a shame that I overlooked this glaring explanation, xwero. Which brings to mind so many reasons I don't bother with the new Form_validation library...

My apologies for introducing such an errant argument to this discussion.
#8

[eluser]Chris Newton[/eluser]
Are you using the validation library? Or the form_validation library?
#9

[eluser]Colin Williams[/eluser]
Old-school validation, mahuti. Sorry for the mixup.
#10

[eluser]Chris Newton[/eluser]
I was referring to 'smickiedoo' above, the OP.




Theme © iAndrew 2016 - Forum software by © MyBB