![]() |
CI removes the "0" from the values - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: CI removes the "0" from the values (/showthread.php?tid=22444) Pages:
1
2
|
CI removes the "0" from the values - El Forum - 09-09-2009 [eluser]DeaD SouL[/eluser] hey there.. I'm facing a problem with the sent values from a form there is a text input in my form called "cat_code" and it might have zero digit "0" (without quotes) in the beginning but CI removes them automatically.. any ideas how can i keep them from being removed? thanks a lot in advance ![]() CI removes the "0" from the values - El Forum - 09-09-2009 [eluser]BrianDHall[/eluser] Hm, I didn't know it did that - are you setting form validation rules? If so, which ones? CI removes the "0" from the values - El Forum - 09-09-2009 [eluser]DeaD SouL[/eluser] here is my validation rule Code: $this->form_validation->set_rules('cat_code' , 'Category\'s Code' , 'trim|integer|required|xss_clean'); but even if i remove that rule.. it still removes the zeros ![]() CI removes the "0" from the values - El Forum - 09-09-2009 [eluser]BrianDHall[/eluser] Hm, indeed odd, I'm not able to test it myself at the moment, but have you tried running var_dump on $_POST and var_dump on the value returned by $this->input->post('cat_code') to ensure they are coming back empty? As a lark, try explicitly casting the returned value to an integer - I _think_ that turns even an empty string into 0, but I can't remember for sure. CI removes the "0" from the values - El Forum - 09-10-2009 [eluser]Michael Wales[/eluser] It's the typecasting to an integer that is doing it. 00123 is not an integer, 123 is. You need to handle your category codes as strings. Code: <?php CI removes the "0" from the values - El Forum - 09-10-2009 [eluser]BrianDHall[/eluser] Wow, I entirely mis-read the thread topic, my bad. I read that 0 was turning into an empty string - not that it had zero-fill at the beginning of a number. Oops. Michael Wales is dead on - if '00123' is a string, it will come out '00123', but if it is an integer it will be '123' because integers don't get zero-filled. After all, no one says "I'm going to turn 040 soon"...but that damned James Bond doesn't play by such rules with his '007'. Ole James never plays by the rules... Yes, so specifically when you assign a value to your form be sure it is in quotes, such as: Code: <input name="category" value="00123"> If the value isn't surrounded in quotes it'll be treated as an integer. CI removes the "0" from the values - El Forum - 09-14-2009 [eluser]DeaD SouL[/eluser] i'm sorry for being late.. i didn't use the manual inputs.. here check my code... the template: Code: $cat_code = array( and this is the rule Code: $this->form_validation->set_rules('cat_code' , 'Category\'s Code' , 'trim|required|xss_clean'); and it still removes them...! thanks bros ![]() CI removes the "0" from the values - El Forum - 09-14-2009 [eluser]BrianDHall[/eluser] Check the HTML that form outputs. For fun, maybe try form_input("$cat_code") and see what it's HTML output is as well ![]() CI removes the "0" from the values - El Forum - 09-14-2009 [eluser]DeaD SouL[/eluser] i just did here is the "add category" page Code: <input type="text" name="cat_code" value="" id="cat_code" size="90" style="width:98%;" /> and this is the "edit category" page Code: <input type="text" name="cat_code" value="321654987" id="cat_code" size="90" style="width:98%;" /> as you can see the quotes are there.. but it still removes the "zeros" please guys... i really do need some help and thanks for everyone that tried or will try to help CI removes the "0" from the values - El Forum - 09-14-2009 [eluser]Jay Logan[/eluser] Is it posting to a database? If so, is your "cat_code" field set to accept leading zeros? Shouldn't just be set for INT. |