Skip to main content
September 14, 2009
Question

Flash Form with CF Validation - Not working

  • September 14, 2009
  • 1 reply
  • 637 views

I've been trying to add some password validation to an existing Flash form within a CF app - I'm re-using some code in a CFC that I'm already using for a standard HTML Change Password form - which is working fine

Within the Admin section of the app there is a set of User Admin forms all held within a <cfformgroup> tags and inside a Flash form - I've tried adding the code as a call before the form is processed but it only picks up certain error conditions and I've tried putting the validation on the Submit button as an onClick event - Which is also ignored

What is the best way to do this properly - It seems such a simple task that is completely throwing me (I'm a recent convert to Coldfusion from Java so still feeling my way to a certain extent!)

My code call from the process form is

     <cfif isdefined("NewPassword") and NewPassword NEQ "">
        <cfinvoke component="global.util.PasswordUtils"
                         method="CheckPasswordStrength"
                      namedUser="#UserName#"
                      oldPassword="#Password#"
                      newPassword="#NewPassword#"
                      confirmPassword="#ConfirmPassword#"                    
                      returnvariable="passswordOK"                     
                      />

And the code within the submit onClick event is:

onClick="if( NewPassword.length > 0 ){
                         if( NewPassword.length < 8 ){    
                            alert('Password must be at least 8 characters.');
                        }else if(hash(NewPassword)==Password){
                            alert('The old and new passwords cannot be the same, please try again');
                        }else if(UserName == NewPassword){
                            alert('The username and password cannot be the same, please try again');
                        }else if(NewPassword != ConfirmPassword){
                            alert('Password and Confirmation must match, please try again');
                        }else {

                            submitForm();

                        }">

Any help would really be appreciated

Thanks

    This topic has been closed for replies.

    1 reply

    BKBK
    Community Expert
    Community Expert
    September 14, 2009

    A number of suggestions.
    1) The script that runs upon onClick should be Javascript or Actionscript, not CFML(Coldfusion). So convert your script accordingly;
    2) In any case, I would define the script in a function, validate() say, then do onClick="validate()";
    3) You should consider using <cfform> and <cfinput>, which offer rich possibilities for clientside validation;
    4) Coldfusion is handy for serverside validation. The commonest way to do so is at the form's action page. For example,

    <cfset isValidationPassed = false>
    <cfif isdefined("form.NewPassword") and form.NewPassword NEQ "">
        <!--- Validation of form variables goes here --->
        <!--- if validation succeeds, set isValidationPassed to true --->
        <cfif isValidationPassed>
            <cfinvoke component="global.util.PasswordUtils"
                      method="CheckPasswordStrength"
                      namedUser="#form.UserName#"
                      oldPassword="#form.Password#"
                      newPassword="#form.NewPassword#"
                      confirmPassword="#form.ConfirmPassword#"                   
                      returnvariable="passswordOK"                    
                      />
        <!--- More business code here and/or possibly redirect to another page --->
    <cfelse>
        <!--- code to send client back to the form page. Give client indication why validation failed --->
    </cfif>