1
Peekay
Commas in the price in Catads 1.4. Can anyone help?
  • 2006/8/30 19:46

  • Peekay

  • XOOPS is my life!

  • Posts: 2335

  • Since: 2004/11/20


CatAds is a fine module (IMHO), but I *know* my users will try to use full-stops in the price field to create values like 4.99 instead of 5. Plus, if you are selling a house, 200,000 looks right where 200000 doesn't. At present, Catads demands a whole number only.

Anyway, I have a partial solution, but I've hit a bit of a dead end. I am hoping someone who understands more about how modules work can complete the puzzle!

Step 1) To allow commas and full stops, I understand that the database needs to accept characters as well as numbers. So I changed 'price' in the 'catads_ads' table from 'INT' to 'VARCHAR(15)'. If I've read my MySQL book properly, VARCHAR(15) should allow an entry like 100,000,000.00 - which should be enough for a classified ad.

Step 2) Next, I modified 'submit1.php' to allow users to enter characters as well as numbers and added a regular expression to check the syntax. If you want to try this, backup the file, then:

Around line 102 change:

if (isset($price) && $price != '' && !is_numeric(trim($price))) $msgstop.= _MD_CATADS_INVALIDPRICE.'<br />';


to:

if (isset($price) && $price != '' && (!ereg("^(([0-9]+)|([0-9]{1,3})(,[0-9]{3})*)(.[0-9]{2})?$"trim($price) ))) $msgstop.= _MD_CATADS_INVALIDPRICE.'<br />';


And around line 243 change:

if (isset($price) && $price != '' && !is_numeric(trim($price) )) {
$msgstop.= _MD_CATADS_INVALIDPRICE.'<br />';
$price '';


to:

if (isset($price) && $price != '' && (!ereg("^(([0-9]+)|([0-9]{1,3})(,[0-9]{3})*)(.[0-9]{2})?$"trim($price) ))) {
$msgstop.= _MD_CATADS_INVALIDPRICE.'<br />';
// $price = '';


This allows entries like 1,234 or 1,234.56 or 1234 or 4.99. Anything else should trigger the warning notice.

Step 3) This is where I'm stuck. The above changes do work (for me) if I preview the ad... but not when I submit it. There's no error, but entering '1,234' results in '1' - the comma truncates the value.

I believe the value needs escaping somewhere on it's journey to the database, but I have no idea where.

Any advice (read solution) would be welcome!
A thread is for life. Not just for Christmas.

Login

Who's Online

190 user(s) are online (127 user(s) are browsing Support Forums)


Members: 0


Guests: 190


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Mar 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits