• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to handle form validation with bulk editing?

#1
[eluser]jprateragg[/eluser]
While in the midst of converting my existing application to the CI framework, I've run into another stumbling block. One of the modules in my application allows me to bulk edit items. Here is my view:

Code:
foreach($cash_flow as $key => $value) {
?>
<tr>
<td>&lt;?php echo $j; ?&gt;
<td>&lt;input type="checkbox" name="delete[&lt;?php echo $value-&gt;id; ?&gt;]" value="1" /&gt;&lt;/td>
<td>&lt;?php echo $value->cat_desc; ?&gt;</td>
<td>&lt;input type="text" name="historical[&lt;?php echo $value-&gt;id; ?&gt;]" value="&lt;?php echo set_value('historical['. $value-&gt;id .']', $value-&gt;historical); ?&gt;" /&gt;&lt;/td>
<td>&lt;input type="text" name="projected[&lt;?php echo $value-&gt;id; ?&gt;]" value="&lt;?php echo set_value('projected['. $value-&gt;id .']', $value-&gt;projected); ?&gt;" /&gt;&lt;/td>
<td>&lt;input type="text" name="adjusted[&lt;?php echo $value-&gt;id; ?&gt;]" value="&lt;?php echo set_value('adjusted['. $value-&gt;id .']', $value-&gt;adjusted); ?&gt;" /&gt;&lt;/td>
</tr>
&lt;?php
echo form_hidden('cash_flow_category_id['. $value->id .']', $value->cash_flow_category_id);
$j++;
}

The value contained in $value->id is the unique id of the record being edited.

How would I use this in conjunction with $this->form_validation->set_rules? How can I set messages for which record/row need to be fixed? I tried this:

Code:
$arr = $this->input->post('cash_flow_category_id');

foreach($arr as $key) {
$this->form_validation->set_rules('cash_flow_category_id['. $key .']', 'Cash Flow Category', 'required|clean_int|cash_flow_check_values');
$this->form_validation->set_rules('historical['. $key .']', 'Historical Value', 'default_zero|clean_dec');
$this->form_validation->set_rules('projected['. $key .']', 'Projected Value', 'default_zero|clean_dec');
$this->form_validation->set_rules('adjusted['. $key .']', 'Adjusted Value', 'default_zero|clean_dec|greater_than[11000]');
}

But I don't get any errors returned for the last rule (greater than 11,000) when I have several rows with values below that. I appreciate any help. Thanks!


Messages In This Thread
How to handle form validation with bulk editing? - by El Forum - 12-05-2012, 02:25 PM
How to handle form validation with bulk editing? - by El Forum - 12-06-2012, 03:29 PM
How to handle form validation with bulk editing? - by El Forum - 12-06-2012, 05:32 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.