[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">
<?php echo form_open('entprdetails/saveindustry',$attributes,$hidden); ?>
<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>
<?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;
?>
<td width="50%">
<?php echo form_checkbox('subcategory[]', $id, FALSE); echo ' '.$c_name; ?>
</td>
<?php
if($i%2==0)
{
?>
</tr> <tr>
<?php
}
?>
<?php
$i++;
}
}
?>
</tr>
<tr>
<td colspan="2">
<?php
if(form_error('subcategory'))
{
$err=form_error('subcategory');
$err=substr($err,3,100);
?>
<span class="notification-input ni-error"><?php echo $err; ?></span>
<?php
}
?>
</td>
</tr>
</table>
<div align="center">
<fieldset>
<input class="submit-green" type="submit" value="Save Changes" />
</fieldset></div>
<?Php echo form_close(); ?>
</div> <!-- End .module table -->
</div> <!-- End .module -->
</div> <!-- End .grid_8 -->
</div> <!-- End .container_12 -->
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.