Solved

JQuery Validation & ColdFusion -- Live Lookup

Posted on 2010-11-29
12
542 Views
Last Modified: 2012-05-10
I am trying to use a live lookup to determine if a screenName is already in use.

I found the this example on the adobe forums, but I can't seem to get it to work...

http://forums.adobe.com/thread/447754

Everything input into the screen name input is returned as if it is already in the database.

Firebug outputs this...

params:
method      checkScreenName
returnformat      json

post:
Parameters     application/x-www-form-urlencoded
screenName      2nornot

Source
screenName=2nornot

response:
false

html:
false

I appreciate any help.
<script id="register" type="text/javascript">

$(document).ready(function() {

	// validate signup form on keyup and submit

	var validator = $("#registerForm").validate({

		rules: {

			screenName: {

				required: true,

				minlength: 2,

				remote: {

					url:"http://localHost:8500/myCigarHub.com/org/cigarHub/cigarHub.cfc?method=checkScreenName2&returnformat=json",

					type:"post"

				}

			},

		},

		messages: {

			screenName: {

				required: "Enter a username",

				minlength: jQuery.format("Enter at least {0} characters"),

				remote: jQuery.format("{0} is already in use")

			},

},



...</script>



   <!--- Check Username --->

    <cffunction name="checkScreenName" access="remote" output="true" returnformat="JSON">

		<cfargument	name="screenName" type="string" required="yes" default="">

		

		<cfset var screenNames = StructNew() />

		<cfset screenNames.found = false />

		

		<cfset var data = "">

		

		<cfquery name="data" datasource="cigarUsers">

		SELECT screenName

		FROM users

		WHERE screenName = <cfqueryparam cfsqltype="cf_sql_varchar" value="ARGUMENTS.SCREENNAME">

		</cfquery>

		

		<cfif data.recordCount GTE 1>

			<cfset screenNames.found = true />

		</cfif>

		<cfoutput>#SerializeJSON(screenNames.found)#</cfoutput>

    </cffunction>

Open in new window

0
Comment
Question by:av8or16
  • 5
  • 4
  • 3
12 Comments
 
LVL 25

Expert Comment

by:dgrafx
ID: 34240810
use <cfqueryparam cfsqltype="cf_sql_varchar" value="#ARGUMENTS.SCREENNAME#">
note the ## around arguments.screenname
0
 

Author Comment

by:av8or16
ID: 34240892
That was a dumb miss on my part.

However, the problem still persists.

"False" is returned each time regardless of whether a match was found in the database or not.
0
 

Author Comment

by:av8or16
ID: 34240931
I had the true/false in reverse.  This works now...

    <!--- Check Username --->
    <cffunction name="checkScreenName" access="remote" output="true" returnformat="JSON">
            <cfargument      name="screenName" type="string" required="yes" default="">
            
            <cfset var screenNames = StructNew() />
            <cfset screenNames.found = true />
            
            <cfset var data = "">
            
            <cfquery name="data" datasource="users">
            SELECT screenName
            FROM users
            WHERE screenName = <cfqueryparam cfsqltype="cf_sql_varchar" value="#ARGUMENTS.SCREENNAME#">
            </cfquery>
            
            <cfif data.recordCount GTE 1>
                  <cfset screenNames.found = false />
            </cfif>
            <cfoutput>#SerializeJSON(screenNames.found)#</cfoutput>
    </cffunction>
0
 
LVL 25

Accepted Solution

by:
dgrafx earned 250 total points
ID: 34240939
ok - you need to return the data

<cfif data.recordCount GTE 1>
<cfset screenNames.found = true />
</cfif>
<CFRETURN screenNames.found />
</cffunction>
0
 
LVL 52

Assisted Solution

by:_agx_
_agx_ earned 250 total points
ID: 34240944
First ensure checkScreenName() works manually.

<cffunction name="checkScreenName" output="true"
<cfoutput>#SerializeJSON(screenNames.found)#</cfoutput>


I haven't tested it but noticed the thread mentioned output should be false.  Also, the <cfoutput> seems odd. I'm assuming they meant to use cfreturn instead:

     ...
     <cfreturn SerializeJSON(screenNames.found)>
</cffunction>
0
 
LVL 25

Expert Comment

by:dgrafx
ID: 34240949
yeah - ya did - i didn't catch that either!!!
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 52

Expert Comment

by:_agx_
ID: 34240962
Glad you figured it out.  Though i'm still puzzled why they're using cfoutput ;-)
0
 

Author Comment

by:av8or16
ID: 34241068
Thanks for the help.  Its working great now.

One last question (jQuery)...

when the initial response comes back and it has found a record in the database, the validation message says "XYZ is already in use" which is what I want it to display.

If I set the focus on another input and go back to the screen name input and change it to another screen name that is taken, the response changes to "[object Object] is already in use".

Any suggestions?
0
 
LVL 52

Expert Comment

by:_agx_
ID: 34241432
I'm not getting that result. Can you post a small runnable example (2 form fields and the js code)?
0
 

Author Comment

by:av8or16
ID: 34245584
I have posted a test form at:

http://www.cigarhub.com/registertest.cfm

validation can be found in firebug:

<script id="register"...

To Replicate:

type av8or11 into the screen name field.

It will correctly display that 'av8or11' is already in use.

However, now

1.  click in the other text box,
2.  then go back to screen name,
3.  then back to the other field.

It will switch to [object Object] is already in use.

This is not a major problem since I can simply change the text display to a static 'Screen Name is taken'.

I am a novice at javascript and jQuery and am more just curious as to why this is happeing.

Thanks
0
 
LVL 25

Expert Comment

by:dgrafx
ID: 34247759
js access is denied error ...

change the url where you have localhost to the same url you have running in the browser
0
 

Author Comment

by:av8or16
ID: 34249047
Ok.  It is up an running now.

http://www.cigarhub.com/registertest.cfm

0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now