Ask a Question related to Coldfusion - Getting Started, Design and Development.
-
ojoonline00 #1
onValidate and a query?
hi,
I have an 'add user' form. I would like to use onValidate in the CFFORM to
check for two things in the username field:
a) that the username doesn't already exist in the database
b) that the username does not have spaces.
How do I use query results in javascript like that? Something to do with the
recordcount I would guess?
<cfquery name="getDuplicate" datasource="#application.db#"
username="#application.un#" password="#application.pw#">
select * from qUser
where User_Username = '#form.User_Username#'
</cfquery>
<cfinput type="text" name="User_Username" required="yes"
onValidate="getDuplicate" message="The username already exists. Please try
again.">
thanks for your help!
jo
ojoonline00 Guest
-
Query of Query to select a title first letter
The column "title" exists in a normal query. Need to select the first letter of the titles to build a list for a prev-next alphabetical search. ... -
Query of Queries on query New type query
In CF5 we have a page that creates a query, using queryNew and querySetCell and the like, we then used dbtype="query" and gave it's name so we could... -
Convert a query to a list, or find an item in a query
Hi All, I am using CFPOP to retrieve mail from a server, then delete each message after I retrieve it. What I want to do is to check that I don;t... -
CAML Query: Multiple Query Fields Issue
I need to Create a CAML Query Dynamically with VB to a Sharepoint WebService GetListItems Method. The User Could Select 1 to X Number of IDs... -
BCP query out executed by xp_cmdshell works fine from query analyzer but fails from VB Component
Hi all, I have a stored procedure which returns a vast number of record and i have to write the output into a csv file. I'm using BCP utility to... -
PaulH *TMM* #2
Re: onValidate and a query?
ojoonline00 wrote:
what ver of cf? if it's 7 & you either don't mind some flash or this is> I have an 'add user' form. I would like to use onValidate in the
> CFFORM to check for two things in the username field:
part of a bigger user management function (ie make the whole thing
flash), then maybe consider flash forms & remoting (but *not* if it's a
simple throw away form--the flash forms overhead might not be worth the
better user experience).
you can't except if you use a hidden frame or some kind of ajax> How do I use query results in javascript like that? Something to do
> with the recordcount I would guess?
methodology. js is clientside, your getDuplicate query is server side.
for a flash form solution, maybe something like this:
<!--- in your myRemoting.cfc --->
<cfcomponent>
<cffunction name="checkUser" returntype="boolean" hint="checks user
name in db" access="remote">
<cfargument name="userName" required="Yes" type="string" hint="user
name to check">
<cfset var getDuplicate="">
<cfquery name="getDuplicate" datasource="someDSN">
SELECT User_Username
FROM qUser
WHERE User_Username = '#arguments.User_Username#'
</cfquery>
<cfif getDuplicate.recordCount>
<cfreturn true>
<cfelse>
<cfreturn false>
</cfif>
</cffunction>
</cfcomponent>
<!--- in your flash form --->
<cfform format="Flash">
<cfformitem type="script">
function checkUser() {
//create connection
<cfoutput>
var connection:mx.remoting.Connection =
mx.remoting.NetServices.createGatewayConnection("h ttp://#cgi.HTTP_HOST#/flashservices/gateway/");
</cfoutput>
//declare service
var myService:mx.remoting.NetServiceProxy;
var responseHandler = {};
responseHandler.onResult = function( results: Object ):Void {
if (results == true) {
_root.User_Username.text=""; // clear existing
alert("User name already exists, please try another.");
}
}
responseHandler.onStatus = function( stat: Object ):Void {
//if there is any error, show an alert
alert("Error while calling cfc:" + stat.description);
}
//get service
myService = connection.getService("cfc.myRemoting", responseHandler );
//make call
myService.checkUser(_root.User_Username.text);
} //checkuser function
</cfformitem>
<cfinput type="text" name="User_Username" required="yes"
onchange="checkUser()">
</cfform>
PaulH *TMM* Guest
-
BKBK #3
Re: onValidate and a query?
Hi Ojoonline00,
You've run the query on the server side anyway, so the bulk of the work has
been done. What you ask for, a combination of server-side code and client-side
Javascript validation, is an unnecessary complication, if at all possible.
The server puts control in your hand. I would just go for it and impose a
direct demand from headquarters, like:
<cfif getDuplicate.RecordCount GT 0>
The username already exists. Please try again.
</cfif>
BKBK Guest



Reply With Quote

