Welcome Guest, Not a member yet? Register   Sign In
Problem With Validation
#1

[eluser]Shiju S S[/eluser]
I have a form. The subcategory field is validated. But I am not getting the form validation error. So I used a hidden field just to check and got the error for validation. I could not figure what was the error.
Code:
<?Php
[b]$hidden = array('entid' => '');[/b]
$attributes = array('class' => 'customForm', 'id' => 'customForm');
?>  
<div class="container_12">
<div class="grid_12">
<div class="module">
<h2 align="center"><span>Edit Industry Category</span></h2>
<div class="module-table-body">
&lt;?php echo form_open('entprdetails/saveindustry',$attributes,$hidden); ?&gt;
<table id="myTable">
<thead>
<th>Please check all those that apply<span> *</span></th>
<th><span> When you save changes, all previous selections will be cleared. </span> </th>
</thead>
              <tr>
               &lt;?Php
     $query="SELECT n_subcategoryid,c_subcategory,c_category FROM subcategory s,category c where s.n_categoryid=c.n_categoryid order by c.n_priority";
     $result = $this->global_db->get_results($query);
     $i=1;
     if($result)
     {
      foreach($result as $row)
    
      {
    
       $c_name= $row->c_category.': '.$row->c_subcategory;
    
       $id=$row->n_subcategoryid;
     ?&gt;

<td width="50%">
&lt;?php echo form_checkbox('subcategory[]', $id, FALSE); echo ' '.$c_name; ?&gt;

                  </td>
         &lt;?php  
         if($i%2==0)
         {
         ?&gt;
                </tr> <tr>
                  &lt;?php  
         }

        ?&gt;


                  &lt;?php  
       $i++;
         }

         }

        ?&gt;  

                  

                  

                  </tr>
                  <tr>
                  <td colspan="2">
                                 &lt;?php
                                    if(form_error('subcategory'))
                                    {
          $err=form_error('subcategory');
                                        $err=substr($err,3,100);
                                    ?&gt;
                                    <span class="notification-input ni-error">&lt;?php echo $err; ?&gt;</span>
                                    &lt;?php
                                    }
                                    ?&gt;                    
                  </td>
                  </tr>
                
</table>
<div align="center">
                                
  <fieldset>
   &lt;input class="submit-green" type="submit" value="Save Changes" /&gt;
  </fieldset></div>
&lt;?Php echo form_close(); ?&gt;
</div>  &lt;!-- End .module table --&gt;
</div>  &lt;!-- End .module --&gt;
</div> &lt;!-- End .grid_8 --&gt;
</div> &lt;!-- End .container_12 --&gt;
And controller
Code:
public function saveindustry()
{
  $data['title'] = "Global Franchise - Start and Develop Your Business";
  $data['meta'] = "Global Franchise - Start and Develop Your Business
  franchisor, franchisee, entrepreneurs, businesss, develop business, business oppertunity";
  $this->load->view('entprarea/header', $data);
  $this->load->view('entprarea/dashboard/menuheader', $data);
  
  $this->form_validation->set_rules('subcategory', 'Industry Category', 'required|xss_clean');

  if ($this->form_validation->run() == FALSE)
  {
  
   $this->load->view('entprarea/dashboard/editindustry_form', $data);
  }
  else
  {
   $entid = $this->session->userdata('entid');
   $this->db->where('n_entid', $entid);
   $this->db->delete('entprsubcategory');
  
   $subcategory=$this->input->post('subcategory');
   while (list ($key,$val) = @each ($subcategory))
   {
    $tabdata = array(
       'n_entid' => $entid ,
       'n_subcategory' => $val ,
    );
    $result=$this->db->insert('entprsubcategory', $tabdata);    
   }
    if($result)
    {
    
     $tabdata = array( 'b_updatestatus' => '1');
     $this->db->where('n_entid', $entid);
     $this->db->update('entrepreneur_details', $tabdata);
          
     $data['message']="Industry  category updated sucessfully";
     $data['classid']="notification n-success";
     $data['urllink']="franchisee";
     $this->load->view('adminarea/showmessage', $data);
    }
    else
    {
     $data['message']="This franchisee was not found";
     $data['classid']="notification n-error";
     $data['urllink']="franchisee";
     $this->load->view('adminarea/showmessage', $data);
    }        
    
  }
  
  $this->load->view('entprarea/footer', $data);
} // end of editindustry
Quote:The form error is not shown when the hidden field is removed. But is returning back to the form.




Theme © iAndrew 2016 - Forum software by © MyBB