• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
validation not populateing %s in error message

For some reason when I do my validation it is not populating the error message with the field name. So my messages end up looking like this "The field must contain a valid email address." Instead of "The Email field must contain a valid email address".

Any idea why this would be happening?

maybee you could post some code up...

make sure you call set_fields as well, as this call is used to build up the error messages I seem to recall from memory (i.e. <fieldname>_error). that is if you are using the form validation.. I am only assuming you are.

    $rules['username']    = "required";
    $rules['password']    = "required";
    $rules['passconf']    = "required";
    $rules['email']        = "required";
    $fields['username']    = 'Username';
    $fields['password']    = 'Password';
    $fields['passconf']    = 'Password Confirmation';
    $fields['email']    = 'Email Address';

&lt;?php echo $this->validation->username_error; ?&gt;
&lt;input type="text" name="username" value="&lt;?php echo $this-&gt;validation->username;?&gt;" size="50" />


I'm using the auth module so here's what I can show you.

Form display
<p class="clearfix">
                    <label for="email">Email</label>
                           'value'=>(isset($this->validation) ? $this->validation->{$this->config->item('auth_user_email_field')} : ''),
                    &lt;?=(isset($this->validation) ? $this->validation->{$this->config->item('auth_user_email_field').'_error'} : '')?&gt;

                <p class="clearfix">
                    <label for="user_name">Login</label>
                           'value'=>(isset($this->validation) ? $this->validation->{$this->config->item('auth_user_name_field')} : ''),
                     &lt;?=(isset($this->validation) ? $this->validation->{$this->config->item('auth_user_name_field').'_error'} : '')?&gt;

                <p class="clearfix">
                    <label for="password">Password</label>
                           'value'=>(isset($this->validation) ? $this->validation->{$this->config->item('auth_user_password_field')} : ''),
                       &lt;?=(isset($this->validation) ? $this->validation->{$this->config->item('auth_user_password_field').'_error'} : '')?&gt;


                <p class="clearfix pass_conf">
                    <label for="password_conf">Password<br />Confirmation</label>
                           'value'=>(isset($this->validation) ? $this->validation->{$this->config->item('auth_user_password_confirm_field')} : ''),
                      &lt;?=(isset($this->validation) ? $this->validation->{$this->config->item('auth_user_password_confirm_field').'_error'} : '')?&gt;

Here is what is in the auth controller
function register()
    $rules[$this->config->item('auth_user_name_field')] = $this->config->item('auth_user_name_field_validation_register');
        $rules[$this->config->item('auth_user_password_confirm_field')] = $this->config->item('auth_password_required_confirm_validation')."|matches[".$this->config->item('auth_user_password_field')."]";
        $rules[$this->config->item('auth_user_password_field')] = $this->config->item('auth_user_password_field_validation_register');
        $rules[$this->config->item('auth_user_email_field')] = $this->config->item('auth_user_email_field_validation_register');
        if ($this->config->item('auth_use_country'))
            $rules[$this->config->item('auth_user_country_field')] = $this->config->item('auth_user_country_field_validation_register');
        if ($this->validation->run() && $this->authlib->register())

try putting somthing like
$fields[$this->config->item('auth_user_name_field')]                = 'User Name';
$fields[$this->config->item('auth_user_password_field')]            = 'Password';
$fields[$this->config->item('auth_user_password_confirm_field')]    = 'Password Confirm';
$fields[$this->config->item('auth_user_email_field')]               = 'Email';

if ($this->config->item('auth_use_country')) {
  $fields[$this->config->item('auth_user_country_field')] = 'Country';
when you call $this->validation->set_fields I belive the error message replacement strings are being built up, so 'Email' will be added in the errormessage 'The Email must contain a valid email address'

I havnt used auth.. but it looks like its still using the form validation routines so the principles should be the same.

Thank you! This helped me solve the problem. These were being defined in the modules constructor and there were no values being assigned to the field names. I appreciate the assistance.

I want to Know that How i can find that there is duplicte email address exist in db.
plz i cannot understand it.
if a user fillup a signup form. It might be his enterd email address is already in db. i want a code such like that.
help me
best regard
Amjad Farooq

no probs, glad it helped.


I wont write the code for you, but I can point you in the right direction.. you should read and understand CI 'validation' class in the documentation..

once you have done that take a look at the section Callbacks: Your own Validation Functions in the validation documentation.

what you need to do is write a callback function that will do a select on the database using the email entered from the form (this will be passed as a parameter into the callback function).. then if the query returns a result then you know it already exists in the database. If the email exists in the database you call the $this->validation->set_message and return FALSE, otherwise you return TRUE.

hope this helps.

thanks i have made it possible with your guidence thanks again

your welcome.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.