Welcome Guest, Not a member yet? Register   Sign In
Validation Issue
#1

(This post was last modified: 08-16-2024, 10:56 AM by munggaran. Edit Reason: add hope )

Just got my project updated to CI 4.5.4, most of the issue solved by following guide and internet forum, but this I found by myself and currently tweak bit my code for compatibility with latest update:

Issue:
Validation field now will not accept number, even has been passed as string like (string)$myvariable , this will still raise an error.

Step to produce:
Just make database field name using only number e.g. field "111" or "222", make validation such as required/string/int/etc then it will raise an error when running validation.

Hope in the future this could be fixed because I use number as field number, adding prefix into code is somewhat challenging risk of bug.
Reply
#2

Thank you for reporting!

We don't know this issue. Can you show the exact whole error message?
And what version of CI4 did work?
Reply
#3

MySQL states that all columns with all numbers must be enclosed in double quotes.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#4

(This post was last modified: 08-22-2024, 03:04 PM by munggaran.)

(08-16-2024, 07:46 PM)kenjis Wrote: Thank you for reporting!

We don't know this issue. Can you show the exact whole error message?
And what version of CI4 did work?
Code:
=========================
Type Error
str_contains(): Argument #1 ($haystack) must be of type string, int given

SYSTEMPATH\Validation\Validation.php at line 172
LINE 172:
if (str_contains($field, '*')) {
=========================

This works in CI 4.0, number as field names still accepted.

Other bugs that I found is when I put only "trim" as validation then this will raise same error, I just want to make sure that user put something instead string with spaces, but this can be escalated by adding regex into validation for now. I read from internet trim in 4.0 was converted into boolean while 4.5.4 just null, this probably leads into validation error.
Reply
#5

Thank you. I got your issue.

I sent a PR to fix the bug: https://github.com/codeigniter4/CodeIgniter4/pull/9142
Reply
#6

(This post was last modified: 08-22-2024, 04:46 PM by kenjis.)

(08-22-2024, 12:16 PM)munggaran Wrote: Other bugs that I found is when I put only "trim" as validation then this will raise same error, I just want to make sure that user put something instead string with spaces, but this can be escalated by adding regex into validation for now. I read from internet trim in 4.0 was converted into boolean while 4.5.4 just null, this probably leads into validation error.

The trim() function accept a string as the first parameter.
See https://www.php.net/manual/en/function.t...escription

So if you pass other than a string value, now the error occurs.

Type checking in PHP is becoming stricter, so type checking in CI4 is also becoming stricter.
To avoid errors, please change so that only strings are passed.

Also, because CI4 does not change the data to be validated, specifying trim in the validation rules is meaningless even in 4.0.
Reply
#7

I’ve faced similar issues with field names as numbers. The stricter type-checking in CI 4.5.4 can be tricky. Looking forward to the fix in the PR.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB