![]() |
Form validation with radio buttons when updating form - 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: Form validation with radio buttons when updating form (/showthread.php?tid=26246) |
Form validation with radio buttons when updating form - El Forum - 01-09-2010 [eluser]sdotsen[/eluser] I have a form that pulls data from a database. Code works fine if it's an input box but I can't get the latest $_POST data for radio buttons. This works for input text box. I get default values pulled from the DB on first load, and I can get the new input (if any) from the user modifies the input box on a failed validation. Code: <?php echo form_input('email',set_value('email', $email)); ?> Here's the code for one of my radio button. It works when I'm pulling data from the DB, but if the form refreshes due to a failed validation, I'm not sure how I can show what the user selected. Code: <input type="radio" name="gender" value="male" <?php if($gender == "male") echo "checked"; ?> />Male I played around with set_radio but i ran into the same issue. Form validation with radio buttons when updating form - El Forum - 01-09-2010 [eluser]gigas10[/eluser] Code: <input type="radio" name="gender" value="male" <?php if(set_value('gender', $gender) == "male") echo "checked"; ?> />Male Try that Form validation with radio buttons when updating form - El Forum - 11-03-2010 [eluser]Selene[/eluser] I still cannot get my saved radio box information to redisplay on the form. Have you been able to get this to work? Form validation with radio buttons when updating form - El Forum - 11-04-2010 [eluser]LuckyFella73[/eluser] I had the same problem and came to this solution: Code: // Controller part where you get data from database: If somebody knows a better/cleaner/more portable way to do that I would be happy to read here EDIT: After submitting the form I then have this in case the validation didn't went trough: Code: $data['gender'] = $this->input->post('gender'); Form validation with radio buttons when updating form - El Forum - 11-04-2010 [eluser]Selene[/eluser] Thank you LuckyFella73 I will try you solution when I get home from this job to work on my other job. |