![]() |
Validation for Dynamically Added Fields - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Validation for Dynamically Added Fields (/showthread.php?tid=4052) |
Validation for Dynamically Added Fields - El Forum - 11-04-2007 [eluser]BrandonDurham[/eluser] I've got a form where the user can dynamically add extra fields with javascript and I'd like to be able to validate those fields, if possible. Has this been discussed before? Any ideas? If it helps they'll all have similar names, like track_1, track_2, etc. Thanks! Validation for Dynamically Added Fields - El Forum - 11-05-2007 [eluser]xwero[/eluser] you could do something like Code: $postkeys = array_keys($_POST); Validation for Dynamically Added Fields - El Forum - 11-05-2007 [eluser]BrandonDurham[/eluser] I'll give that a shot. Thank you! Validation for Dynamically Added Fields - El Forum - 11-05-2007 [eluser]Pygon[/eluser] alternatively, you could pass the keys by array -- instead of track_1, track_2, you can use track[] -- this will return an array of values: Example Only: Code: <form method="post" action="processForm.php"> and Code: $aTrack = $this->input->post('track'); Validation for Dynamically Added Fields - El Forum - 11-09-2007 [eluser]Paulo Eduardo[/eluser] Pygon, If i use a array like you say how i do to repopulate the form if some data as posted wrong? `cuz i try something like that: Code: $this->validation->username[0] if have you a solution for that i will be Grateful Thanks a lot Paulo Eduardo Validation for Dynamically Added Fields - El Forum - 11-10-2007 [eluser]Pygon[/eluser] I can't give you exact code at the moment, since I'm at home, but I would suggest that you print_r your array to see how it is populated (and whether you've correctly accessed the array). Validation for Dynamically Added Fields - El Forum - 01-14-2008 [eluser]Symcrapico[/eluser] [quote author="Paulo Eduardo" date="1194689333"]Pygon, If i use a array like you say how i do to repopulate the form if some data as posted wrong? `cuz i try something like that: Code: $this->validation->username[0] if have you a solution for that i will be Grateful Thanks a lot Paulo Eduardo[/quote] Anyone has a head up on this? Im facing the same problem and I have no idea on how to repopulate my form. Here my simplified form: Code: <div id="formJoueur" class="formJoueur"> As you can see, I have 3 dynamic fields that I need to validate and repopulate, nomJoueur[], noChandail[] and noPasseport[]. I cant wait to see a solution for that! Thanks Validation for Dynamically Added Fields - El Forum - 01-14-2008 [eluser]Michael Ekoka[/eluser] The native library doesn't support these features. I've tried to fix this for myself and posted my solution here. Validation for Dynamically Added Fields - El Forum - 01-14-2008 [eluser]eggshape[/eluser] Hi: View file: Code: // makes array from data retrieved via database and passed to view Controller: Code: public function validate() That works for me. I use this strategy when I want to validate dynamic or *special* fields on the fly, depending on the choices the user makes or does not make. It basically involves running your own validate() method which sets the custom validation rules and then run the CI validate function on submit. EDIT: I should be clear that the form's action is "controller/validate"...validate() is called on form submission and not submit(). And I use the default validation file for 1.5.4 |