1

Craft 3 is giving me this error when my client enters non-numeric characters into a number field on an entry:

number_format() expects parameter 1 to be float, string given

Is there a way for it to check and remove non-numeric characters from the field on save? Or maybe my setup is incorrect?

  • Is it an error or an exception? Because it actually should display errors rather than removing the characters. You could create a custom field that strips all letters from the input – Robin Schambach Oct 31 '18 at 15:22
  • Per an image my client sent: PHP Warning - yii\base\ErrorException – Indigo Viking Oct 31 '18 at 15:25
  • Shouldn't craft handle this natively? Either not allowing non-numeric characters in number fields or something? – Indigo Viking Oct 31 '18 at 15:26
3

Just tested this on a local Craft3 setup and here's what I discovered...

If the decimal points setting on the number field is set to 0, adding text in the number field will display the pretty errors below:

enter image description here

If the decimal points setting is set to anything else, you get the Twig error mentioned in the title of this post:

number_format() expects parameter 1 to be float, string given

I'd recommend opening an issue in the Craft CMS repo as I imagine the number field ought to display the pretty errors no matter if decimal points is set or not.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.