I currently have a form with over 50+ fields, with roughly 20 optional fields.
Is there any easy way to process $_POST data in one hit to remove empty strings and change them to NULL prior to inserting into the database, or do they have to be done one by one in the following method:
if ($_POST['field_x'] == "") {
$_POST['field_x'] = NULL;
}
You can use array_filter:
http://php.net/manual/en/function.array-filter.php
To only remove empty strings you can use:
If you don’t want to drop values, but only want to set them to NULL: use
array_map: