validation not populateing %s in error message - El Forum - 05-17-2008
[eluser]cwpollock[/eluser]
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?
validation not populateing %s in error message - El Forum - 05-17-2008
[eluser]gtech[/eluser]
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.
Code: ..
$rules['username'] = "required";
$rules['password'] = "required";
$rules['passconf'] = "required";
$rules['email'] = "required";
$this->validation->set_rules($rules);
$fields['username'] = 'Username';
$fields['password'] = 'Password';
$fields['passconf'] = 'Password Confirmation';
$fields['email'] = 'Email Address';
$this->validation->set_fields($fields);
..
view
Code: <h5>Username</h5>
<?php echo $this->validation->username_error; ?>
<input type="text" name="username" value="<?php echo $this->validation->username;?>" size="50" />
//etc
....
validation not populateing %s in error message - El Forum - 05-17-2008
[eluser]cwpollock[/eluser]
I'm using the auth module so here's what I can show you.
Form display
Code: <p class="clearfix">
<label for="email">Email</label>
<?=form_input(array('name'=>$this->config->item('auth_user_email_field'),
'id'=>$this->config->item('auth_user_email_field'),
'maxlength'=>'120',
'value'=>(isset($this->validation) ? $this->validation->{$this->config->item('auth_user_email_field')} : ''),
'class'=>'text'))?>
<?=(isset($this->validation) ? $this->validation->{$this->config->item('auth_user_email_field').'_error'} : '')?>
</p>
<p class="clearfix">
<label for="user_name">Login</label>
<?=form_input(array('name'=>$this->config->item('auth_user_name_field'),
'id'=>$this->config->item('auth_user_name_field'),
'maxlength'=>'45',
'size'=>'45',
'value'=>(isset($this->validation) ? $this->validation->{$this->config->item('auth_user_name_field')} : ''),
'class'=>'text'))?>
<?=(isset($this->validation) ? $this->validation->{$this->config->item('auth_user_name_field').'_error'} : '')?>
</p>
<p class="clearfix">
<label for="password">Password</label>
<?=form_password(array('name'=>$this->config->item('auth_user_password_field'),
'id'=>$this->config->item('auth_user_password_field'),
'maxlength'=>'16',
'value'=>(isset($this->validation) ? $this->validation->{$this->config->item('auth_user_password_field')} : ''),
'class'=>'text'))?>
<?=(isset($this->validation) ? $this->validation->{$this->config->item('auth_user_password_field').'_error'} : '')?>
</p>
<p class="clearfix pass_conf">
<label for="password_conf">Password<br />Confirmation</label>
<?=form_password(array('name'=>$this->config->item('auth_user_password_confirm_field'),
'id'=>$this->config->item('auth_user_password_confirm_field'),
'maxlength'=>'16',
'value'=>(isset($this->validation) ? $this->validation->{$this->config->item('auth_user_password_confirm_field')} : ''),
'class'=>'text'))?>
<?=(isset($this->validation) ? $this->validation->{$this->config->item('auth_user_password_confirm_field').'_error'} : '')?>
</p>
Here is what is in the auth controller
Code: 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');
$this->validation->set_rules($rules);
if ($this->validation->run() && $this->authlib->register())
{
redirect('/home/registered/');
}
else
{
$this->db_session->flashdata_mark();
$this->register_index();
}
}
validation not populateing %s in error message - El Forum - 05-17-2008
[eluser]gtech[/eluser]
after
$this->validation->set_rules($rules);
try putting somthing like
Code: $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';
}
$this->validation->set_fields($fields);
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.
validation not populateing %s in error message - El Forum - 05-19-2008
[eluser]cwpollock[/eluser]
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.
validation not populateing %s in error message - El Forum - 05-19-2008
[eluser]Shahgeb[/eluser]
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
validation not populateing %s in error message - El Forum - 05-19-2008
[eluser]gtech[/eluser]
@cwpollock:
no probs, glad it helped.
@amjadfarooq:
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.
validation not populateing %s in error message - El Forum - 05-19-2008
[eluser]Shahgeb[/eluser]
thanks i have made it possible with your guidence thanks again
validation not populateing %s in error message - El Forum - 05-20-2008
[eluser]gtech[/eluser]
your welcome.
|