Copy link to clipboard
Copied
Sorry i am very new to ColdFusion and English is not my first language, please forgive me if have any mistake.
I am looking for some technique like search form or form filter.
This is a reference .
It is a hotel finding website.
My question is here, how to use coldfusion to create this kind of searching form with ajax?
Please give me some idea or tips , i will appreciate with you assist !
I have just get some idea on ajax search form with text.
<form>
Search: <input type="text" name="search">
<input type="button" value="Search">
</form>
<cfdiv bind="url:movieresults.cfm?search={search}">
</cfdiv>
It is depend on the url.
How about other like checkbox , select?
Its exacly what I thought it will be :
Notice this :
<cfinvoke component="test2"
method="sendFeatures" argumentCollection="#args#" returnvariable="results">
Compare to yours :
<cfinvoke component="test2"
method="sendFeatures" search="#args#" returnvariable="results">
Do you see the diffrence ?
This is why you add a ARGUMNET.SEARCH.Feature_ID istead of ARGUMNET.Feature
So Change the INVOKE statement and it should work now
And IT will be good for you (if you want to be able to solve thin
...Copy link to clipboard
Copied
example for you to work with :
cfajaximport>
<cfif isdefined('url.search')>
<cfdump var="#url#">
<cfabort>
</cfif>
<cfform>
<cfinput type="text" name="search">
<cfinput type="checkbox" name="checkbox1" checked="TRUE" value="11">
</cfform>
<cfdiv bind="url:index.cfm?search={search@keyup}&checked={checkbox1.checked@click}&checkboxvalue={checkbox1@click...>
</cfdiv
This will load the index.cfm every time u :
Check/un check the checkbox, and will post the TRUE/FALSE state fo the checkbox - checked={checkbox1.checked@click} // checkboxvalue={checkbox1@click
Type in any text in the text box.
Hope this helps.
Copy link to clipboard
Copied
It is very good example for me ! Thank a lot !
I am trying with it ! thank thank
Copy link to clipboard
Copied
Can i ask another question about the database SELECT ?
the database must SELECT all in 1 cffuntion ?
all can be sepeaate those database SELECT ?
Copy link to clipboard
Copied
I'm not sure I understand your Q' .. can you ask with an example ... it will be easier for me to help out ..
Copy link to clipboard
Copied
If accoding to your example, i don't want the checbox with checked, but i want their default = "". Can set the cfargument default="" ? or use <cfparam> ?
Let say this is my component.
<cfcomponent>
<cfset ds = "Reservation">
<cffunction name="getFeatures"
access="public"
returntype="Query">
<cfset var Features="">
<cfquery name="Features" datasource="#ds#">
SELECT Feature_ID, Feature
FROM Features
</cfquery>
<cfreturn Features>
</cffunction>
<cffunction name="sendFeatures"
returntype="Query"
access="public">
<cfargument name="Feature_ID" type="any" default="">
<cfset var CheckBox ="">
<cfquery name="CheckBox" datasource="#ds#">
SELECT r.Name , r.Restaurant_ID, f.feature
FROM Restaurants r, Bridge1_Restaurant_Features b, Features f
where b.Feature_ID = f.Feature_ID AND b.Restaurant_ID = r.Restaurant_ID
<cfif #ARGUMENTS.Feature_ID# IS NOT "">
AND f.Feature_ID IN (#ARGUMENTS.Feature_ID#")
</cfif>
GROUP BY r.Name
</cfquery>
<cfreturn CheckBox>
</cffunction>
</cfcomponent>
Ok. above is my component, but the content only for checkbox,
if later i will include some input with text or selection ,
there will more table to add on with different input,
my question is i need to set all SELECT database in same <cfquery> or separate them ?
BTW, my component cant get the result,
the result is always default "",
my idea result is will be change when checkbox change.
Copy link to clipboard
Copied
1. Check box CHECKED has 2 optional (only) values : TRUE/FALSE.
2. I'm not sure how u want to pass Feature_ID into the Function, where is that value comeing from ? and what type is it ? INT/CHAR ?
3. about adding more caluses to the WHERE .. no problem as long as you can apply that logic, Ie get all the options under one query. its beter to maintain ONE READ from each table in the database, if not every time u make a change in the db u need to make a chnage in more then one function.
Copy link to clipboard
Copied
I have try a simple way with the checkbox without ajax.
I set a input submit button and when click it the submit will send to result page, it is working with those code almost same with my curreny component code.
Just face problem when wanna make it as ajax.
The feature_ID from table features, and it type is INT.
Copy link to clipboard
Copied
post the code fo were the CFFORM is ...
maybe then I will get what you are tryign to do and why its failing ...
Copy link to clipboard
Copied
talofer99 , i am really appreciate for your patient, thank you !
i post the code that working well without ajax.
<cfquery datasource="Reservation" name="Features">
SELECT Feature_ID, Feature
FROM Features
</cfquery>
<cfform action="Search_Features_Result.cfm">
Feature:
<cfoutput query="Features">
<input type="checkbox"
name="Feature_ID"
value="#Feature_ID#">#Feature# <br />
</cfoutput>
</cfform>
---------------------------------------------------------------------------------------------------
<cfparam name="FORM.Feature_ID" default="">
<cfquery name="Restaurants" datasource="Reservation">
SELECT r.Name , r.Restaurant_ID, f.feature
FROM Restaurants r, Bridge1_Restaurant_Features b, Features f
where b.Feature_ID = f.Feature_ID AND b.Restaurant_ID = r.Restaurant_ID
<cfif FORM.Feature_ID IS NOT "">
AND f.Feature_ID IN (#FORM.Feature_ID#)
</cfif>
GROUP BY r.Name
</cfquery>
<cfoutput query="Restaurants">
#Restaurant_ID# </br>
#Name#
<
</cfoutput>
Copy link to clipboard
Copied
ok can u now post the DIV BIND u created ?
Copy link to clipboard
Copied
<cfinvoke component="test2"
method="getFeatures"
returnvariable="Features">
<cfoutput query="Features">
<input type="checkbox"
name="Feature_ID"
value="#Feature_ID#"
>#Feature# <br />
</cfoutput>
<cfdiv bind="url:test2a.cfm?checkboxvalue={Feature_ID@click}">
------------------------------------------------------------------------------------------------------------
<cfparam name="url.checkboxvalue" default="">
<cfinvoke component="test2"
method="sendFeatures" search="#url.checkboxvalue#" returnvariable="results">
<cfoutput query="results">
#Restaurant_ID#
#Name#
</cfoutput>
--------------------------------------------------------------------------------------------------------
this is cfc file
<cfcomponent>
<cfset ds = "Reservation">
<cffunction name="getFeatures"
access="public"
returntype="Query">
<cfset var Features="">
<cfquery name="Features" datasource="#ds#">
SELECT Feature_ID, Feature
FROM Features
</cfquery>
<cfreturn Features>
</cffunction>
<cffunction name="sendFeatures"
returntype="Query"
access="public">
<cfargument name="Feature_ID" type="any" default="">
<cfset var CheckBox ="">
<cfquery name="CheckBox" datasource="#ds#">
SELECT r.Name , r.Restaurant_ID, f.feature
FROM Restaurants r, Bridge1_Restaurant_Features b, Features f
where b.Feature_ID = f.Feature_ID AND b.Restaurant_ID = r.Restaurant_ID
<cfif #ARGUMENTS.Feature_ID# IS NOT "">
AND f.Feature_ID IN (#ARGUMENTS.Feature_ID#")
</cfif>
GROUP BY r.Name
</cfquery>
<cfreturn CheckBox>
</cffunction>
</cfcomponent>
Copy link to clipboard
Copied
Your problem is in the INVOKE
<cfinvoke component="test2"
method="sendFeatures" search="#url.checkboxvalue#" returnvariable="results">
Search IS NOT ANY OF THE CFC ARGUMNETS ...
So you need to pass the Vlue in ..
useing :
argumentCollection = "argument collection"
So it needs to look like this :
<cfset args = structnew()>
<cfset args.Feature_ID = url.checkboxvalue>
<cfinvoke component="test2"
method="sendFeatures" argumentCollection="#args#" returnvariable="results">
To match the
<cfargument name="Feature_ID" type="any" default="">
Next time CFDUMP the ARGUMNETS inside the CFC ,,, this wil lallwo you to "see" what goes into the CFC ....
Have fun
Copy link to clipboard
Copied
Thank talofer99.
i have modify result page to
<cfset args = structnew()>
<cfset args.Feature_ID = url.checkboxvalue>
<cfinvoke component="test2"
method="sendFeatures" argumentCollection="#args#" returnvariable="results">
then i get the error
Called from C:\wamp\www\Test\test2a.cfm: line 5
Called from C:\wamp\www\Test\test2.cfc: line 27
Called from C:\wamp\www\Test\test2a.cfm: line 525 : where b.Feature_ID = f.Feature_ID AND b.Restaurant_ID = r.Restaurant_ID
26 : <cfif #ARGUMENTS.Feature_ID# IS NOT "">
27 : AND f.Feature_ID IN (#ARGUMENTS.Feature_ID#")
i have try to change the arguments became args have to same error.
by the way, i am asking a silly question, sorry, how to CFDUMP in arguments ?
Copy link to clipboard
Copied
remove the DBLQUOTE in the end of this
AND f.Feature_ID IN (#ARGUMENTS.Feature_ID#") <--- this dbl quote ... This iswhy Iasked u what type of FIELD is the id .. I noticed the unneeded " before ..
and to dump the variables
<cfdump var="#arguments#">
Copy link to clipboard
Copied
Ops sorry, i did not notice the double quote. it is my fault.
It is working without error, but the result would not change any more, keep maintain with default.
I try to tick few of the checkbox, it only change the value in the column of the search.
Column feature_ID only with empty string.
struct | |||||
---|---|---|---|---|---|
FEATURE_ID | [empty string] | ||||
SEARCH |
|
Copy link to clipboard
Copied
IS this the DUMP of the ARGUMNETS struct insdie the CFC ?
If so, somthign is still not ok ... can u post the code of the page that populate the div output ?
Do you understand the structure output ?
and what is not ok ?
Notice that the FEATURE_ID is EMPTY
and then you have SEARCH STRUCT that contain this : FEATURE_ID ...
So once you will show how you cretae the structure I can tell you where its going wroung
Copy link to clipboard
Copied
so in thoury if it is the dump of the ARGUMENTS colletion inside the cfc
if yo uto do this :
<cfif #ARGUMENTS.Feature_ID# IS NOT "">
27 : AND f.Feature_ID IN (#ARGUMENTS.Search.Feature_ID#)
It should work ..
but its better to pass the info in currectly .... then to "fix" it inside the cfc
Copy link to clipboard
Copied
This is the file of test.cfm
<cfinvoke component="test2"
method="getFeatures"
returnvariable="Features">
<form>
<cfoutput query="Features">
<input type="checkbox"
name="Feature_ID"
value="#Feature_ID#"
check="false">#Feature# <br />
</cfoutput>
<cfdiv bind="url:test2a.cfm?checkboxvalue={Feature_ID@click}">
</form>
----------------------------------------------------------------------------------------------------------------------
this is the file of test2a.cfm
<cfparam name="url.checkboxvalue" default="">
<cfset args = structnew()>
<cfset args.Feature_ID = url.checkboxvalue>
<cfinvoke component="test2"
method="sendFeatures" search="#args#" returnvariable="results">
<cfoutput query="results">
<tr>
<td>#Restaurant_ID#</td>
<td>#Name#</td>
</tr>
</cfoutput>
----------------------------------------------------------------------------------------------------------------------
this is the cfc file
<cfcomponent>
<cfset ds = "Reservation">
<cffunction name="getFeatures"
access="public"
returntype="Query">
<cfset var Features="">
<cfquery name="Features" datasource="#ds#">
SELECT Feature_ID, Feature
FROM Features
</cfquery>
<cfreturn Features>
</cffunction>
<cffunction name="sendFeatures"
returntype="Query"
access="public">
<cfargument name="Feature_ID" type="any" default="">
<cfset var CheckBox ="">
<cfquery name="CheckBox" datasource="#ds#">
SELECT r.Name , r.Restaurant_ID, f.feature
FROM Restaurants r, Bridge1_Restaurant_Features b, Features f
where b.Feature_ID = f.Feature_ID AND b.Restaurant_ID = r.Restaurant_ID
<cfif #ARGUMENTS.Feature_ID# IS NOT "">
AND f.Feature_ID IN (#ARGUMENTS.Search.Feature_ID#)
</cfif>
GROUP BY r.Name
</cfquery>
<cfdump var="#arguments#">
<cfreturn CheckBox>
</cffunction>
</cfcomponent>
Copy link to clipboard
Copied
Its exacly what I thought it will be :
Notice this :
<cfinvoke component="test2"
method="sendFeatures" argumentCollection="#args#" returnvariable="results">
Compare to yours :
<cfinvoke component="test2"
method="sendFeatures" search="#args#" returnvariable="results">
Do you see the diffrence ?
This is why you add a ARGUMNET.SEARCH.Feature_ID istead of ARGUMNET.Feature
So Change the INVOKE statement and it should work now
And IT will be good for you (if you want to be able to solve things like this on your own) to learn about structrues and the use of them...
Copy link to clipboard
Copied
OMG !@! It is working pretty well now ! !!
Sorry it is my mistake again , feel so sorry to u.
Yup, i will continue improve my coldfusion !
This is one of my school assignment , so abit rushing with it !
Really wanna say thoudsand thank to you !! !
Really nice to meet you
Copy link to clipboard
Copied
You welcom ...
enjoy CF its a very powerfull platform ...
Copy link to clipboard
Copied
Yeah , it is powerfull platform.
I have a long journey for learning .
Copy link to clipboard
Copied
Can i continue ask some question ? But u have the right to ignore.
If i wanna add another checkbox but different value and table.
Is it i continue the cfdiv became ?
<cfdiv bind="url:Search_Features_Result.cfm?checkboxvalue={Feature_ID@click}&checkboxvalue={Price_ID@click}">
then add one more
<cfset args.Price = url.checkboxvalue>
But i think i can't add 1 more
<cfargument name="Price _ID" type="any" default="">
in the component content.
Copy link to clipboard
Copied
You are makeing mess of things since you don;t spend the time learning the basics of STRUCTURES ....
You can do this :
<cfdiv bind="url:Search_Features_Result.cfm?checkboxvalue={Feature_ID@click} &checkboxvalue={Price_ID@click}">
SHOULD BE
<cfdiv bind="url:Search_Features_Result.cfm?checkboxvalue={Feature_ID@click} &checkboxvalue2={Price_ID@click}">
this
<cfset args.Price = url.checkboxvalue>
Should be
<cfset args.Price = url.checkboxvalue2>
AND THIS CAN NOT BE ... since one line above you called it "Price"
<cfargument name="Price _ID" type="any" default=""> (also notice the unneeded space)
So it can be
<cfargument name="Price" type="any" default="">
OR change the
<cfset args.Price_Id = url.checkboxvalue2>
Names in structure must match .....
And I will go ahead and chaneg the PARAM in the URL to
<cfdiv bind="url:Search_Features_Result.cfm?Feature_ID={Feature_ID@click} &Price_ID={Price_ID@click}">
and then u can invoke the CFC using URL as the ARGUMENTCOLLECTION ... (instead of haveing to buield one ... with <cfset args = structnew()>)
Please refer to the manual and the endless samples on the web for things like that ....