Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0 value reported as empty on non-null field #9

Open
Kitsap-Sun-545 opened this issue Feb 12, 2015 · 1 comment
Open

0 value reported as empty on non-null field #9

Kitsap-Sun-545 opened this issue Feb 12, 2015 · 1 comment

Comments

@Kitsap-Sun-545
Copy link

Greetings, I'm using v1.10

If a field is required (since it's a not null column) and a user enters 0 for that field, an error is thrown during validation stating that the value is empty.

Steps to reproduce:

  1. Create a table with a column that is not null, but where the default is null.
  2. Switch to input mode and try to add a record where that value is 0.

Additional background:

The problem appears to be in the validate_data method of CustomDatabaseTables class in lib/cdbt.class.php

    function validate_data($column_schema, $data) {
            if ($column_schema['not_null'] && $column_schema['default'] == null) {
                    if (empty($data))
                            return array(false, __('empty', self::DOMAIN));
            }
            if (!empty($data)) {

The empty function returns true when $data evaluates as false. See http://php.net/manual/en/function.empty.php for more information.

This means that empty($data) will return true when $data is a string containing the number 0. In my installation I've changed the validate function to explicitly check for empty string or null which then allows me to set 0 values on input or edit.

    function validate_data($column_schema, $data) {
            if ($column_schema['not_null'] && $column_schema['default'] == null) {
                    if ($data == '' || $data == NULL)
                            return array(false, __('empty', self::DOMAIN));
            }
            if ($data != '' && $data != NULL) {
@ka215
Copy link
Owner

ka215 commented Mar 17, 2015

Sorry for my late reply.
And, thank you very much for reporting.

I tried to verify the process that inputting data to table by the plugin.
And, as you say, I also found a few bugs in the data verification part.

I will fix the bugs of data verification process. Then, I am going to try to release in the next version up.

Thank you,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants