1 Replies - 6016 Views - Last Post: 05 April 2017 - 08:15 AM Rate Topic: -----

#1 Gates   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 13
  • Joined: 31-March 17

CFSET var Rereplace and wont insert in Database

Posted 31 March 2017 - 06:47 AM


I'm kinna new to this i'm trying to create a little system for my son lawn mowing business.

i have field that have services and prices for it

services1 price1

services2 price2

When he enters the data for the price i want to prevent him from using commas and dollar sign so when he submits field i'm trying to use this to modify it on the inserting page

price_f1 is the form field so if he puts in 450,50$
   <cfset price1 = ReReplace(price_f1, "[^\d.]", "","ALL") >

<cfoutput>#price1#</cfoutput>  it comes out 45050 i want 450.50 how can i do that ?

And once that works how can i enter it into the database i have tryed to get it in using

<cfinsert datasource="mydatasource" tablename="thetablename" formfields="ID, firstname, lastname...., services1,  price1"></cfinsert>

All the data enters but not my price1 at 45050 it stays NULL any suggestion why that is and yes i do set my var before the insert.

Thank you

Is This A Good Question/Topic? 0
  • +

Replies To: CFSET var Rereplace and wont insert in Database

#2 Craig328   User is offline

  • I make this look good
  • member icon

Reputation: 2042
  • View blog
  • Posts: 3,644
  • Joined: 13-January 08

Re: CFSET var Rereplace and wont insert in Database

Posted 05 April 2017 - 08:15 AM

Welcome to DIC Gates!

So, what you're doing is a form of validation. Trying to prevent characters in a form field these days is best done by using a Javascript function that allows only numbers and a decimal place holder. Or, better still, just numbers and the script formats the entry for you.

I notice you're using CFINSERT for your database work. Most current CF devs have moved away from using the CFFORM related tags as they can be somewhat restrictive and cause the kinds of problems you're experiencing. Your better bet is to use a CFQUERY tag and then a simple INSERT SQL statement contained therein (and remember to use CFQUERYPARAM tags for anything you pass into your database that comes from user input).

DIC has a robust Javascript forum where you can ask questions for how to build out a quick form field screen/validator. Or, you can Google for the same and will likely find dozens of examples on the web.

Good luck!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1