There is a field for price in my form that will be saved in a decimal format into db.
Now if a user types commas ‘,‘ not points ‘.‘, how can I quietly replace it so that it will be saved correctly? eg instead of 12,34, there will be saved 12.34, not 12.00
It would probably be easiest if you used a
CFilterValidatorto convert the input from a string to a float value automatically when validation happens; the rest should take care of itself.So your model would have
and the filtering function would be something like
You can also specify the filtering function as any valid callable, for example make it a model method and specify it as