Welcome Guest, Not a member yet? Register   Sign In
How to check for / insert optional fields?
#5

[eluser]drewbee[/eluser]
No. It should not return an empty string. That is what was passed from the Form ยป 'an empty string'. Values coming from forms are always strings, even when they are numbers, so false or null are not valid options regarding this.

Your saying postgre can't save an empty string. Seems absolutely rediculous to me (remind me never to use that system);

Anyways, I did some reading and it appears you can insert a null value, but not empty. So, I would do something like this. I little bit cleaner, but still a mess. This will simply check all of your post values and convert every empty string to null. May be a good idea to just have this auto run through the form validation extension.

Code:
// Set to null if empty
foreach ($_POST AS $key => $value)
{
    if (empty($value))
    {
        $_POST[$key] = null;
    }
}

$data = array(
    'table_of_contents' => $this->input->post('table_of_contents'),
    'length' => $this->input->post('length'),
    'lossless_copy' => $this->input->post('lossless_copy'));

);

See how that works for you.


Messages In This Thread
How to check for / insert optional fields? - by El Forum - 10-21-2008, 10:50 AM
How to check for / insert optional fields? - by El Forum - 10-21-2008, 12:15 PM
How to check for / insert optional fields? - by El Forum - 10-22-2008, 07:13 AM
How to check for / insert optional fields? - by El Forum - 10-24-2008, 04:12 AM
How to check for / insert optional fields? - by El Forum - 10-24-2008, 09:31 AM



Theme © iAndrew 2016 - Forum software by © MyBB