CodeIgniter Forums
Form Validation Within For Loop issue - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Form Validation Within For Loop issue (/showthread.php?tid=65164)



Form Validation Within For Loop issue - nkhan - 05-09-2016

Hi Everybody. I think you  all are well.

I have been  trying to create a Block module since morning. Where i want add block and all the added block will be listed in just at the bottom of Add a New block section. Please have a look on the attached image it helps you what i am trying to say.Now the question is arise how do i apply form validation rule to add / Update block content. 


Code:
  public function block()
  {
       
        $data['blocks']= $this->block_m->get();
        
        if($this->input->post('addblock')=='Add Block'){
                   
                       $blockrules=$this->block_m->blockrules;    

            $this->form_validation->set_rules($blockrules);

            if ($this->form_validation->run() == TRUE) {
                
                //insert a new block
            }
        }
        if($this->input->post('updateblock')=='Update'){
            
            $id=$this->input->post('block_id');
            
                       $data = $this->block_m->array_from_post(array('block_title','short_code','content'));
            
                       $this->block_m->save($data,$id);
                       
                       $this->session->set_flashdata('updatemsg',"<div class='alert alert-success'>
                       Page #".$id." Updated successfully...</div>");
            
                       redirect('webadmin/settings/block');
            
        }
    
        
        $data['main_content'] = 'webadmin/settings/block';
        $this->load->view('includes/template', $data);     
  }
 

 Thanks


RE: Form Validation Within For Loop issue - InsiteFX - 05-09-2016

It should be:

PHP Code:
if ($this->form_validation->run() == FALSE)
{
    
// show the block form
}
else
{
    
// Submitted successful