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

[BUG]: Forms - ctype_* default values #16064

Closed
niden opened this issue Aug 19, 2022 · 1 comment · Fixed by #16068
Closed

[BUG]: Forms - ctype_* default values #16064

niden opened this issue Aug 19, 2022 · 1 comment · Fixed by #16068
Assignees
Labels
5.0 The issues we want to solve in the 5.0 release bug A bug report status: medium Medium

Comments

@niden
Copy link
Sponsor Member

niden commented Aug 19, 2022

I'm trying v5.0.0RC4 with PHP8.1.
In the class that extends \Phalcon\Forms\Form, we specified validation when defining the element.

            $elm->addValidators([
                new Validator\Digit([
                    'message' => 'Invalid number of reservations',
                    'allowEmpty' => false,
                ]),
                new Validator\Between([
                    'minimum' => 0,
                    'maximum' => 15
                ])
            ]);

I expect it to be a number from 0 to 15, but I want to make an error for other numbers, strings, and unset (null or '').
But with the above configuration, I get this error.
Deprecated: ctype_digit(): Argument of type null will be interpreted as string in the future

This is probably because the specification of ctype_*() has changed since PHP8.1, but Phalcon currently does not support it.

It would allow an unexpected value, but at the moment it's unavoidable, so even if I change it to Validator\Numericality, it won't recognize the posted value.
After trying various things, it seems that there is a problem with the name of the element.

I receive the form data in an array because it takes less time to process it after it is received.
For example:

<input type="number" name="foo[1]" value="" />
<input type="number" name="foo[2]" value="" />
<input type="number" name="foo[3]" value="" />

It is often used in select/option instead of input.
(There are cases where multiple checkboxes are collectively acquired as name="cb[]")
So I write the following in form::initialize().

        $optionAry = array(0,1,2,3);
        $elm = new Element\Select("order[1]", $optionAry, [
            'id' => 'order11',
            'useEmpty' => false,
        ]);

With this, you can get the HTML element with the name with [ ] in the view, but it doesn't seem to understand it during validation.
If you change "order[1]" to "order1", it will be processed without problems, but considering the processing after receiving it, I would like to receive it as an array.
Is it a problem that you can set it and output HTML tags, but you can't validate it?

Originally posted by @s-ohnishi in #16057

@niden niden self-assigned this Aug 19, 2022
@niden niden added bug A bug report status: medium Medium 5.0 The issues we want to solve in the 5.0 release labels Aug 19, 2022
niden added a commit to niden/cphalcon that referenced this issue Aug 23, 2022
niden added a commit to niden/cphalcon that referenced this issue Aug 23, 2022
@niden niden mentioned this issue Aug 23, 2022
5 tasks
@niden niden linked a pull request Aug 23, 2022 that will close this issue
5 tasks
@niden niden added this to Working on it in Phalcon Roadmap Aug 23, 2022
@niden
Copy link
Sponsor Member Author

niden commented Aug 23, 2022

Resolved in #16068

@niden niden closed this as completed Aug 23, 2022
Phalcon Roadmap automation moved this from Working on it to Implemented Aug 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5.0 The issues we want to solve in the 5.0 release bug A bug report status: medium Medium
Projects
Archived in project
Phalcon Roadmap
  
Implemented
Development

Successfully merging a pull request may close this issue.

1 participant