i bet this is making me dive into deep sea due to ...
# lucee
g
i bet this is making me dive into deep sea due to how cf handles data sometimes my form structure is like this posting from datatables
Copy code
draw: 2
columns: id,name,email,texture
order[0][column]: 0 - problem area
order[0][dir]: asc
order[0][name]: 
start: 0
length: 10
search[value]: trf - problem area
search[regex]: false
and i am running a check on server side to see if the arguments.search.value is not empty
Copy code
<cfif structKeyExists(arguments, "search") AND structKeyExists(arguments.search, "value") AND len(trim(arguments.search.value))>
            <cfset sql &= " AND (">
            <cfloop array="#columnList#" index="col">
                <cfif col GT 1>
                    <cfset sql &= " OR ">
                </cfif>
                <cfset sql &= "#col# LIKE '%#arguments.search.value#%'">
            </cfloop>
            <cfset sql &= ")">
        </cfif>
what is wrong here
t
I have a feeling you miss some fundamental #1 Are the data you show in 1st code block comes from your console.log? #2 Are you sure the data posted are available in your arguments scope? I would suggest you do a cfdump var="#FORM#" to see how the data from DataTable got posted to CF first
g
I am sending to cfc and yes that is from console
m
i'm assuming you aren't getting into the if at all right? if so, try using structKeyExists(arguments, "search[value]") and then referencing as arguments["search[value]"] please don't construct the sql that way. the #col# part is fine IF you control columnlist, but if it comes from something that could be populated by client it is a risk. the stuff where you are dropping in the search value, is definitely a sql injection risk in how it is written. if you are using <cfquery> then i'd say the simplest way is to just build an array of column name and values where you are constructing the sql, then within the <cfquery> add a loop on the array and drop those in, with the values in #col# like <cfqueryparam value="%#val#%" cfsqltype="varchar"> . if you are doing queryExecute(), then you can construct the sql like you are doing, just replacing '%#arguments.search.value#%' with :SearchValue and append to your params struct with SearchValue: { value:"%#arguments['search[value]']#%", cfsqltype: "varchar"}
similarly, the order stuff will be referenced as arguments["order[0][column]"]
g
That worked thanks
It was quite simple though and I was not able to crack it
It was evening so I can expect
r
arrays are 1-based in cf
m
@rodyon that isn't a cf array. that is a field name as it is posted from datatables