onValidate and a query?

Ask a Question related to Coldfusion - Getting Started, Design and Development.

  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. Similar Questions and Discussions

    1. 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. ...
    2. 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...
    3. 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...
    4. 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...
    5. 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...
  3. #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

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

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139