⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Show custom error message while insert/edit



abhishek

abhishek
  • profile picture
  • Member

Posted 11 May 2013 - 06:18 AM

Hi All,

 

I want to show a custom error message while inserting a record.

 

Ex:-

$crud->required_fields('projectName','projectPriority','projectCost','projectTimeline','projectEffortEstimate',
            'projectEffortConsumed','projectStartDate','projectsStatus','projectSprintSheet','clientId','typeId');

 

When user try to insert leaving every field empty, It shows a list of error messages and the input fields become red.

 

The Projectname Feild is required.

The projectPriorityFeild is required.

The projectCostFeild is required.

.

.

.and so on.

 

Now, I want it show a single message that  fields marked red  are mandatory.
How to do this.?


jaorsoftware

jaorsoftware
  • profile picture
  • Member

Posted 12 May 2013 - 04:28 AM

Hi Friend

 

I am novice too but i think that i can help you

 

You shoud set rules to validate the fields

 

Example

 

 
$crud = new grocery_CRUD();
$crud->set_theme('datatables');            
$crud->set_table('countrys');
$crud->columns('id','name','has_prov','zones_id');                 
$crud->fields('name','has_prov','zones_id');
$crud->display_as('name','Nombre');
$crud->display_as('has_prov','Tiene Provincias');
$crud->display_as('zones_id','Zona');           
 
 // The next are the rules to validate in the form
//***************************************************************
$crud->set_rules('name','Nombre','required');
$crud->set_rules('zones_id','Zona','required');            
//***************************************************************
// Ejecuta la forma
$output = $crud->render();
$this->_example_output($output);
 
If the user dont capture name o zone_id the form show a message !
 
Regards

davidoster

davidoster
  • profile picture
  • Member

Posted 12 May 2013 - 06:41 AM

In addition to the previous post you need also to use the set_message from the CI's Form Validation class.