PHP8: error with number condition

Resolve a PHP 8 number_format error in a ChronoForms condition.

Overview

The error occurs because PHP 8 enforces strict type checking, and a string value is being passed to the number_format function where a numeric type is required.
Ensure the variable passed to number_format is explicitly cast to an integer or float. Alternatively, avoid using PHP code for this condition by utilizing CF events instead.

Answered
ChronoForms v7
Pi Pigna 01 Mar, 2022
Hi!

In a form I've this condition: if {var:model.name} == 1 the element is visible.

The value in the db is 0 or 1.

WIth J3, CFv7, PHP7 it works, so with J4, CFv7, PHP7.

With J4, CFv7, PHP8 I receive this error:

0 - number_format(): Argument #1 ($num) must be of type float, string given

I can change 0/1 with n/y or others value, anyway I think it's a bug.

p.
Co Colnem 01 Mar, 2022
Hi

Is it personal table or a joomla table in your db?
What is the field format in your table?
Pi Pigna 01 Mar, 2022
Personal table, tinyint.
Co Colnem 01 Mar, 2022
1 Likes
Thanks.

Trying on one personal table with a tinynt field, using Run conditions, I haven't any error...

if {var:model.name} == 1 the element is visible.

Is there a php code?
Pi Pigna 02 Mar, 2022
Answer
Yes, it's a php code problem.

With PHP8 i need to change code like $var = number_format($var, 2, ',', '.') in $var = number_format((int)$var, 2, ',', '.').

Thank's.
Co Colnem 02 Mar, 2022
Hi

In php, you can't use {var:model.name}
You have to use this syntax:
varPhp=$this->get("name_of_var_cf7","");

But to do what you want, you can use CF7 Event, no need PHP.

Bye
This topic is locked and no more replies can be posted.