Form field with dynamic id validation |
How can i validate fields with names like this
Code: <select name="mechanic_134" id="mechanic-134" class="form-control selectpicker"> mechanic_ is the general field name & 134 is a id i am getting from database. there are more fields to come like mechanic_135........mechanic_150. i want to know how can i validate this field with dynamic id. please show it in code level. how it is done in controller & how the error output in view Thanks.
You can check whether the request method is 'post'. If so, take the posted data into an array. Then scan the array for keys that begin with 'mechanic_'. For the detected such keys make the corresponding validation rules and register them. After that you can call if $this->form_validation->run() { ... } else { ... }
(08-26-2016, 10:48 PM)ivantcholakov Wrote: You can check whether the request method is 'post'. If so, take the posted data into an array. Then scan the array for keys that begin with 'mechanic_'. For the detected such keys make the corresponding validation rules and register them. After that you can call if $this->form_validation->run() { ... } else { ... } could you please show this in code level
so i could be wrong but i think it could be something like this - say if you are doing it in a form validation array,
and somehow you get the id in there - which keep in mind could be in a hidden form field PHP Code: array( also keep in mind that you can do form validation in separate methods - so for example you could check that the ID is valid before validating the mechanic field, etc
(08-26-2016, 10:00 PM)greenarrow Wrote: How can i validate fields with names like this Use foreach to check the indexes of all post data. Controller: PHP Code: function validate() Views: <?php echo form_error('mechanic_134') ?> <select name="mechanic_134" id="mechanic-134" class="form-control selectpicker">
[Just a programmer] [/Just a programmer]
|
Welcome Guest, Not a member yet? Register Sign In |