CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • accepting currency values with currency symbols
Pages: [1]

Author Topic: accepting currency values with currency symbols  (Read 684 times)

Sean Madsen

  • I post occasionally
  • **
  • Posts: 98
  • Karma: 5
  • CiviCRM implementer/developer
    • Bikes Not Bombs
  • CiviCRM version: 4.6
  • CMS version: Drupal 7
accepting currency values with currency symbols
April 02, 2015, 11:01:14 am
As discussed here, we'd like Civi to accept money values when entered with a currency symbol. So I made CRM-16221 to keep track of this fix.

I'm trying to fix it, both because I want the fix for my org, and also because I'm trying to learn more about the code base. (I'm new to developing with Civi.) So I'm trying to really do this fix the right way. No hacks. I want feedback here.

The CRM_Utils_Rule::cleanMoney() function seems like a clear place to apply this fix. I tried changing the first line to read as follows:

$value = str_replace(array(" ", "\t", "\n", "$", "¥", "£"), '', $value);

And this works well. When testing with an amount of "$23", I get to the confirmation screen with no errors. Strange part is that the confirmation screen is the missing the "Contribution Amount", "Billing Name and Details", and "Credit Card Information" sections on the screen. The only sections I have on the confirmation page are the sections generated from data entered through my profile fields for the contribution page.

What is even more strange is that if I test with an amount of "2$3", everything works as expected and I see all sections on the confirmation page.

I'd love some help here. Trying to bridge the gap to become a developer after many years of user/implementer.

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: accepting currency values with currency symbols
April 02, 2015, 11:06:33 am
Not sure this is it but try placing those currency symbols in single quotes instead of double. Like '$' instead of "$".
The dollar sign has a special meaning in php and needs to be escaped in double-quotes.
Try asking your question on the new CiviCRM help site.

Sean Madsen

  • I post occasionally
  • **
  • Posts: 98
  • Karma: 5
  • CiviCRM implementer/developer
    • Bikes Not Bombs
  • CiviCRM version: 4.6
  • CMS version: Drupal 7
Re: accepting currency values with currency symbols
April 02, 2015, 11:20:50 am
Quote
try placing those currency symbols in single quotes instead of double

I tried this but it behaved exactly the same. Also tried "\$" (same behavior), and '\$' (which causes my test to fail validation).

I've also watched this function run through a de-bugger and seen $value go from $20 to 20, so it seems to me that the mischief is outside of this function.

Thanks for the tip though! Still curious how to fix this!

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: accepting currency values with currency symbols
April 04, 2015, 05:33:53 pm
I think the clientside solution might be best, would give instant feedback to users by removing non-numeric characters from the field.
Are you familiar with jQuery?
Try asking your question on the new CiviCRM help site.

Sean Madsen

  • I post occasionally
  • **
  • Posts: 98
  • Karma: 5
  • CiviCRM implementer/developer
    • Bikes Not Bombs
  • CiviCRM version: 4.6
  • CMS version: Drupal 7
Re: accepting currency values with currency symbols
April 06, 2015, 09:03:46 am
Yes, I'm familiar with jQuery and it has occurred to me to approach this issue from that direction. But honestly that feels a bit hack-ish so I'm hesitant to go down that road. Further, since I'm trying to focus my time right now on tasks that help me learn more about the CiviCRM codebase, spending time on the jQuery approach would not be a priority for me, personally. I really want get deeper in to learning how to be a CiviCRM developer. If fixing this issue through the server-side form mechanisms proves too difficult, then I'll move to a different issue that I feel will also help me learn about the inner workings of Civi. Also, just my opinion: In terms of instant feedback to the user (by removing currency symbol), to me this does not seems important if the form would accept values entered with currency symbols.

Still very curious why my original fix caused other problems. Would love to learn how to apply this sort of fix properly!

Sean Madsen

  • I post occasionally
  • **
  • Posts: 98
  • Karma: 5
  • CiviCRM implementer/developer
    • Bikes Not Bombs
  • CiviCRM version: 4.6
  • CMS version: Drupal 7
Re: accepting currency values with currency symbols
April 06, 2015, 12:47:22 pm
For anyone else following along, it turns out this bug has been fixed in CRM-14868.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • accepting currency values with currency symbols

This forum was archived on 2017-11-26.