(03-03-2016, 03:45 AM)keulu Wrote: i already do something like that.
this is my code from scratch
PHP Code:
if ($this->input->post('send')) {
$this->load->library('form_validation');
$index = 0;
for ($index = 0; $index < 100; ++$index) {
if ($this->input->post('host_'.$index.'_templateid') != '') {
if ($this->input->post('host_'.$index.'_zabbix_integration')) {
$this->form_validation->set_rules(
'host_'.$index.'_templateid',
'Choix du template ligne '.$index,
'required|is_natural_no_zero'
);
$this->form_validation->set_rules(
'host_'.$index.'_ip',
'Adresse IP ligne '.$index,
'required|valid_ip'
);
$this->form_validation->set_rules(
'host_'.$index.'_suffixe',
'Suffixe ligne '.$index,
'required'
);
$this->form_validation->set_rules(
'host_'.$index.'_location',
'Emplacement ligne '.$index,
'required'
);
} else {
$this->form_validation->set_rules(
'host_'.$index.'_suffixe',
'Suffixe ligne '.$index,
'required'
);
$this->form_validation->set_rules(
'host_'.$index.'_location',
'Emplacement ligne '.$index,
'required'
);
}
}
}
if ($this->form_validation->run() === true) {
// do you insert/update
}
}
-------------------------------------------------------------------------------
I tried to put the code within my FOR for counting added records, i took the first and the second line of code, as I already carry a library in autoload and within that FOR I have tested if it sent, but has not worked yet. .... I did something like this:
if($this->input->post('cadastrar') === "cadastrar"){
$registros_name = $this->input->post('name');
$registros_user = $this->input->post('user');
$registros_pass = $this->input->post('pass');
$this->load->model('admin/admin_model');
$admin_model = new admin_model();
for($i = 0; $i < count($registros_name); $i++){
//Then i put your code here without the first two lines
$this->form_validation->set_rules('name['.$i.']', 'NAME', 'required|min_length[5]|max_length[30]');
$this->form_validation->set_rules('user['.$i.']', 'USER', 'required|min_length[5]|max_length[30]');
$this->form_validation->set_rules('pass['.$i.']', 'PASS', 'required|min_length[5]|max_length[30]');
if($this->form_validation->run() === TRUE){
//The magic happens
}else{
//The magic does not happen
}
}
//more some code
}