Zero value not allowed in integer field.

14 years 3 months ago #122792 by mware
I have created a series of integer fields with minimum value 0, maximum 100. Unfortunately, zero is not accepted at registration - the error is "Fieldname: This input value is not authorized."

I've searched every post I could find about this issue but have only found that leading zeros are stripped - which makes sense - but are perhaps single zeros being stripped as well?

I know it should be possible to write a text field regex that would accomplish somewhat the same thing, but I'd prefer to use the integer field if at all possible.

Please Log in to join the conversation.

14 years 3 months ago #122798 by mware
After some more digging, I think the problem is in this line of code within class CBfield_integer in plug_cbcore:

[code:1]if ( in_array( (int)$value, $forbiddenContent ) ) {
$this->_setValidationError( $field, $user, $reason, _UE_INPUT_VALUE_NOT_ALLOWED );
$validated = false;
}
[/code:1]

Removing (int) from that first line resolves the issue:

[code:1]if ( in_array( $value, $forbiddenContent ) ) { [/code:1]

Please Log in to join the conversation.

14 years 3 months ago #122801 by beat
Thanks for reporting and suggesting fix directly, highly appreciated B)

I would suggest following fix instead, which takes care of user-inputed leading-zeros, which was the intention of the (int) typecasing:
[code:1] if ( in_array( (string) ( (int) $value ), $forbiddenContent ) ) {
[/code:1]

Can you please confirm that this fix proposal also works for you ?

#1408

Beat - Community Builder Team Member

Before posting on forums: Read FAQ thoroughly -- Help us spend more time coding by helping others in this forum, many thanks :)
CB links: Our membership - CBSubs - Templates - Hosting - Forge - Send me a Private Message (PM) only for private/confidential info

Please Log in to join the conversation.

14 years 3 months ago #122803 by mware
Yes, indeed that works just fine. :-)

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.205 seconds

Facebook Twitter LinkedIn