php - Codeigniter set_value() With Dynamic Multidimensional Array Inputs -
ok, generating form pre-populated existing values db:
view:
<tr> <td><input name="set[<?php echo $cur_set['id']; ?>][order]" value="<?php echo $cur_set['wo_order']; ?>"> <input type="hidden" name="set[<?php echo $cur_set['id']; ?>][ex_id]" value="<?php echo $cur_set['ex_id']; ?>"></td> <td><input name="set[<?php echo $cur_set['id']; ?>][weight]" value="<?php echo $cur_set['weight']; ?>"></td> <td><input name="set[<?php echo $cur_set['id']; ?>][reps]" value="<?php echo $cur_set['reps']; ?>"></td> </tr> example output:
<tr> <td><input name="set[3][order]" value="1"> <input type="hidden" name="set[3][ex_id]" value="1"></td> <td><input name="set[3][weight]" value="50.00"></td> <td><input name="set[3][reps]" value="5"></td> </tr> so have range of these <tr>s each can have unique 'id' have same number of secondary indices [order], [ex_id], [weight] , [reps].
i cannot figure out 2 things:
- how apply set_value() syntax when don't know [id] going be.
how set validation rules on form. have tried:
$this->form_validation->set_rules('set[][order]', 'sets', 'required');
but doesn't seem work set[][order] not found...can put sort of wildcard in there? set[*][order]?
thanks in advance.
jon
in controller, fetch data , store in variable (i'll call $data), this:
$data = $this->model_name->method_name(); foreach($data $set){ $this->form_validation->set_rules("set[{$set['id']}][order]"); $this->form_validation->set_rules("set[{$set['id']}][weight]"); etc... }
Comments
Post a Comment