Welcome Guest, Not a member yet? Register   Sign In
use string helper with currency
#10

[eluser]Michael Nielsen[/eluser]
[quote author="darkhouse" date="1235763582"]There are a few issues here.

First, I don't think you should be using the $_POST array as the 2nd parameter of the insert method. I think you should create a new array so that it only has the values you want.

Next, I think don't think you should be storing the $ in the database with the price data. I think the price field should be set to float, or double in the database, and then you add the $ anywhere you display the price. This solves another issue you might run into down the road. What if you need to make your site display different currencies. Many currencies do not use the $ symbol, nor are they in the same format like $1,234.56. If you store the actual numerical value, you can then use that to display in any currency (after you convert it of course) and not worry about the $ symbol.

Last, I don't know if this is common practice for you, but you should really be using better validation rules. Now, this looks like it's the backend where you're inserting products, but just doing 'required' isn't enough. For the product name, you might want to check a max length, and xss_clean. For the price, you'll want to check numeric.

That's my $0.02[/quote]

Thanks DarkHouse. I understand that the validation rules are very minimal and the reason behind that is that I'm just building the base of the app right now.

As I'm not a seasoned developer would you care to explain (examples) the above methods. Particularly the database.

Also this site is only for New Zealand residence. My goal was to be able to enter a numeric value in the form then before it's entered into the database by the controller have it add $ sign so I don't have to waste time on every entry by manually typing the $ sign.

Could you also further explain putting the data from the form into an arry instead of $_POST


Messages In This Thread
use string helper with currency - by El Forum - 02-26-2009, 10:24 PM
use string helper with currency - by El Forum - 02-26-2009, 10:33 PM
use string helper with currency - by El Forum - 02-26-2009, 11:17 PM
use string helper with currency - by El Forum - 02-26-2009, 11:57 PM
use string helper with currency - by El Forum - 02-27-2009, 12:08 AM
use string helper with currency - by El Forum - 02-27-2009, 01:38 AM
use string helper with currency - by El Forum - 02-27-2009, 01:38 AM
use string helper with currency - by El Forum - 02-27-2009, 01:53 AM
use string helper with currency - by El Forum - 02-27-2009, 07:39 AM
use string helper with currency - by El Forum - 02-27-2009, 01:48 PM
use string helper with currency - by El Forum - 02-27-2009, 04:01 PM
use string helper with currency - by El Forum - 02-27-2009, 05:20 PM
use string helper with currency - by El Forum - 02-27-2009, 06:49 PM
use string helper with currency - by El Forum - 02-28-2009, 02:59 AM



Theme © iAndrew 2016 - Forum software by © MyBB