SELECT User_Username FROM qUser WHERE User_Username = '#arguments.User_Username#' function checkUser() { //create connection var connection:mx.remoting.Connection = mx.remoting.NetServices.createGatewayConnection("http://#cgi.HTTP_HOST#/flashservices/gateway/"); //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 [allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => [ref] => [htmlstate] => on_nl2br [postusername] => PaulH *TMM* [ip] => paul@sustainabl [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 2 [islastshown] => [isfirstshown] => [attachments] => [allattachments] => ) --> onValidate and a query? - Coldfusion - Getting Started

onValidate and a query? - Coldfusion - Getting Started

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...

  1. #1

    Default 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

  2. #2

    Default Re: onValidate and a query?

    ojoonline00 wrote:
    > I have an 'add user' form. I would like to use onValidate in the
    > CFFORM to check for two things in the username field:
    what ver of cf? if it's 7 & you either don't mind some flash or this is
    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).
    > How do I use query results in javascript like that? Something to do
    > with the recordcount I would guess?
    you can't except if you use a hidden frame or some kind of ajax
    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

  3. #3

    Default 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

Similar Threads

  1. Query of Queries on query New type query
    By david_h in forum Coldfusion Database Access
    Replies: 2
    Last Post: May 6th, 08:55 PM
  2. Query of Query LIKE and Wild Card chars
    By Ramboni in forum Coldfusion Database Access
    Replies: 1
    Last Post: May 3rd, 05:09 PM
  3. Convert a query to a list, or find an item in a query
    By Laverda668 in forum Macromedia ColdFusion
    Replies: 2
    Last Post: April 7th, 07:41 PM
  4. CAML Query: Multiple Query Fields Issue
    By Jon F. in forum ASP.NET Web Services
    Replies: 0
    Last Post: May 12th, 08:19 PM
  5. Replies: 1
    Last Post: July 2nd, 09:09 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •