Welcome, Guest
Username: Password: Remember me

TOPIC: [FIXED] $19.95 loads as .95 in a form edit in the backend

$19.95 loads as .95 in a form edit in the backend 16 Mar 2013 07:07 #6945

  • agaudreau
  • agaudreau's Avatar
  • Offline
  • New Member
  • Posts: 7
  • Karma: 1
I am using text fields in my table and if I enter $19.95 in the form, it is saved properly in the database and is the proper value in a var_dump from within the view.html.php for that form but within the displayed form, it is truncated to .95.

It appears as if it is a dollar sign escape issue as if you do not use it as the first character, it works properly.

I have reproduced it in a virgin project within the sandbox so it is not influenced by my version of joomla or anything on my servers.

Edit: V2.5 Compatibility selected.
Last Edit: 16 Mar 2013 07:11 by agaudreau. Reason: Info missing
The administrator has disabled public write access.

Re: $19.95 loads as .95 in a form edit in the backend 16 Mar 2013 09:20 #6947

  • agaudreau
  • agaudreau's Avatar
  • Offline
  • New Member
  • Posts: 7
  • Karma: 1
The problem resides in the generated dom.php within the parse() function.

$html = preg_replace("/<%" . strtoupper($key) . "%>/",$value, $html);

should be:

$html = preg_replace("/<%" . strtoupper($key) . "%>/", str_replace("$","\\$",$value), $html);

in order to escape $'s in $value to prevent preg_replace() from removing the '$xx' from a passed in value of '$xx.xx'.

I see several calls to preg_replace() within your generated code so you should escape them as well in order to prevent problems elsewhere in your code.
The administrator has disabled public write access.

Re: $19.95 loads as .95 in a form edit in the backend 16 Mar 2013 09:32 #6948

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
Hi @agaudreau and welcome!

Good find! Karma++

I would suggest though, if you are storing prices to use a decimal field and not a string to ensure data integrity for calculations that you will probably need to do in the future. It would just be a case of prepending the '$ ' to the value to display to the user.

Hope this helps!

Gez
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
The administrator has disabled public write access.

Re: $19.95 loads as .95 in a form edit in the backend 19 Aug 2013 18:39 #10833

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
Finally fixed.

Thank for you patience.
Coding is now a piece of cake
The administrator has disabled public write access.
Time to create page: 0.077 seconds

Get Started