- Posts: 2
- Thank you received: 0
Potential bug not stripping commas from donor edit
- James
- Topic Author
- Offline
- New Member
-
Less
More
10 years 2 months ago #57258
by James
Potential bug not stripping commas from donor edit was created by James
Hi OSSolution,
Just a quick message to let you know that i believe i have found a bug in the donor edit screen of JoomDonation v3.8.
The issue arises when there is an amount that is over $1000 which is formatted by using PHP's number_format function. By default, this function formats numbers over 1000 to include commas ',' for readability. However it also appears that during the save process in the component does not strip out the commas successfully and causes the amount to be equal to the number before the comma. (eg. $2,250 saves as $2)
Below is the code line in question: (administrator/com_jdonation/views/donor/tmpl/default.php : line 62
In order to get around the issue of the amounts saving incorrectly, i have made an update to the line in question.
I updated number_format to include the extra 2 features of the function to format both the '.' and then the normal ',' as as a blank.
I added in str_replace around $this->item->amount as a precaution in case the amount comes through with a comma.
I also inserted the same string replacement javascript that is present in the front-end for formatting the amount as it is being entered to reduce the human error. This is the same as the "deSelectRadio();" functions section for stripping commas out.
I'm unsure if this is fixed in your most recent versions, but i thought i would share this just in case it hadn't been found.
P.S. It is very hard to post actual code because apparently everything seems to count as an SQL injection.
Just a quick message to let you know that i believe i have found a bug in the donor edit screen of JoomDonation v3.8.
The issue arises when there is an amount that is over $1000 which is formatted by using PHP's number_format function. By default, this function formats numbers over 1000 to include commas ',' for readability. However it also appears that during the save process in the component does not strip out the commas successfully and causes the amount to be equal to the number before the comma. (eg. $2,250 saves as $2)
Below is the code line in question: (administrator/com_jdonation/views/donor/tmpl/default.php : line 62
Code:
<input type="text" class="input-small" name="amount" value="[php] echo $this->item->amount > 0 ? number_format($this->item->amount, 2) : ""; [/php]" size="7" />
In order to get around the issue of the amounts saving incorrectly, i have made an update to the line in question.
Code:
<input type="text" class="input-small" name="amount" value="<?php echo $this->item->amount > 0 ? number_format($this->item->amount), 2, '.', '') : "";?>" size="7" onchange="clearCommas();"/>
I updated number_format to include the extra 2 features of the function to format both the '.' and then the normal ',' as as a blank.
I added in str_replace around $this->item->amount as a precaution in case the amount comes through with a comma.
I also inserted the same string replacement javascript that is present in the front-end for formatting the amount as it is being entered to reduce the human error. This is the same as the "deSelectRadio();" functions section for stripping commas out.
I'm unsure if this is fixed in your most recent versions, but i thought i would share this just in case it hadn't been found.
P.S. It is very hard to post actual code because apparently everything seems to count as an SQL injection.
Please Log in or Create an account to join the conversation.
- Tuan Pham Ngoc
- Offline
- Administrator
-
10 years 2 months ago #57315
by Tuan Pham Ngoc
Replied by Tuan Pham Ngoc on topic Potential bug not stripping commas from donor edit
Hi James
Thanks for reporting the issue. I think we can simply change number_format to round and the issue should be fixed (simple like that). Could you please try ?
Tuan
Thanks for reporting the issue. I think we can simply change number_format to round and the issue should be fixed (simple like that). Could you please try ?
Tuan
Please Log in or Create an account to join the conversation.
- James
- Topic Author
- Offline
- New Member
-
Less
More
- Posts: 2
- Thank you received: 0
10 years 2 months ago #57340
by James
Replied by James on topic Potential bug not stripping commas from donor edit
You are correct, I think round() should give a better result.
I will test as soon as I am able and report back.
I think the onchange javascript call will still be needed in addition to the PHP change.
James
I will test as soon as I am able and report back.
I think the onchange javascript call will still be needed in addition to the PHP change.
James
Please Log in or Create an account to join the conversation.
- Tuan Pham Ngoc
- Offline
- Administrator
-
10 years 2 months ago #57350
by Tuan Pham Ngoc
Replied by Tuan Pham Ngoc on topic Potential bug not stripping commas from donor edit
I don't think we need to add javascript. Please try the suggested change and report back the reason
Thanks James
Tuan
Thanks James
Tuan
Please Log in or Create an account to join the conversation.
Moderators: Mr. Dam, Dũng Nguyễn Việt
Support
Documentation
Information
Copyright © 2025 Joomla Extensions by Joomdonation. All Rights Reserved.
joomdonation.com is not affiliated with or endorsed by the Joomla! Project or Open Source Matters.
The Joomla! name and logo is used under a limited license granted by Open Source Matters the trademark holder in the United States and other countries.
The Joomla! name and logo is used under a limited license granted by Open Source Matters the trademark holder in the United States and other countries.