![]() |
(02-27-2019, 01:10 PM)php_rocs Wrote: @b126, Hi, Thank you but it’s not a question of isset(), or empty() or ===‘’. It’s a question on how to trigger this conversion automatically while posting the form data or during the validation. Unfortunately, it seems that CI posts empty string if you do not put anything in your input field, like it is the case for optional fields for example. So when a user leave a blank field for an optional input like « distance », the input->post(‘distance’) value posted is ‘’. When you convert ‘’ to an integer in php, it becomes 0. You will then record 0 in your database instead of NULL. The same is for empty strings. You will save ‘’ in your database instead of null. In Laravel, you can use the ConvertEmptyStringsToNull middleware. In Symfony, I think you can use empty_data option. So I wonder if there was an equivalent in Codeigniter. |
Messages In This Thread |
Can I convert empty strings to NULL with a Codeigniter validation rule? - by b126 - 02-27-2019, 08:40 AM
RE: Can I convert empty strings to NULL with a Codeigniter validation rule? - by php_rocs - 02-27-2019, 01:10 PM
RE: Can I convert empty strings to NULL with a Codeigniter validation rule? - by b126 - 02-27-2019, 01:30 PM
RE: Can I convert empty strings to NULL with a Codeigniter validation rule? - by php_rocs - 02-27-2019, 03:58 PM
RE: Can I convert empty strings to NULL with a Codeigniter validation rule? - by b126 - 02-27-2019, 04:11 PM
RE: Can I convert empty strings to NULL with a Codeigniter validation rule? - by dave friend - 02-28-2019, 12:25 PM
RE: Can I convert empty strings to NULL with a Codeigniter validation rule? - by b126 - 02-28-2019, 12:45 PM
RE: Can I convert empty strings to NULL with a Codeigniter validation rule? - by dave friend - 02-28-2019, 01:39 PM
|