• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
single error message for all the validations?

#1
Hi, take a look at the code:
PHP Code:
[
        
'field'  => 'action',
        
'label'  => 'in',
        
'rules'  => 'required|alpha|max_length[5]',
        
'errors' => [
            
'required'   => 'Something missing!',
            
'alpha'      => 'Something missing!',
            
'max_length' => 'Something missing!'
        
]
    ] 

as you can already guess that i am trying to hide the default error messages and override each of them with a custom string, is there any way to do it once? Like this:
PHP Code:
[
        
'field'  => 'action',
        
'label'  => 'in',
        
'rules'  => 'required|alpha|max_length[5]',
        
'default_error' => 'Something missing!';
    ] 
Reply

#2
You could use the error_array() function for this purpose.

PHP Code:
$error_array $this->form_validation->error_array();
if (
is_array($error_array ) && !empty($error_array)) {

 
   // Generate a single message for all fields combined:
 
   echo '<div class="error">Something is wrong with the form values.</div>';

 
   // Or loop through the errors and output a message per fieldname
 
   foreach($error_array  as $fieldname => $message) {
        
// The $message variable contains the message you want to hide
 
       echo '<div class="error">There is a problem with the value for the ' $fieldname ' field.</div>';
 
   }


Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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