1 Reply Latest reply on Jul 6, 2007 9:48 AM by denvermax

    CFSELECT validation in Flash format form

    denvermax
      In the past, I have used Javascript validation in CFFORMs to validate CFSELECT input, due to the bug in Coldfusion validation (most of my client sites are on shared servers, so I can't modify the cfform.js file).

      The Javascript I found somewhere worked great:

      <!-- Validation Functions -->
      <SCRIPT LANGUAGE = "JavaScript">

      function ExtendJS(FormName) {
      if (!SingleSelectRequired(FormName,'Event_Description')) {
      alert("You must select a Vendor from the drop-down list.");
      return false;
      }
      }

      function
      SingleSelectRequired(Form, Field) {
      var itemSelected =
      eval("document." + Form + "."
      + Field + ".selectedIndex");
      if (itemSelected == 0) {
      return false;
      } else {
      return true;
      }
      }
      </SCRIPT>

      Then, in my CFFORM tag:
      <cfform
      name = "formName"
      action = "index.cfm?section=4&submit=1"
      preservedata="Yes"
      enctype = "multipart/form-data"
      method = "POST"
      format = "HTML"
      onSubmit = "return ExtendJS('FormName')">

      Now I'm exploring CFFORM format="Flash"... well, not just exploring, way down the road developing a web app ... and I've discovered my old validation methods don't work. It seems I have to use Actionscript now.

      Does anyone have a good Actionscript form validation implementation they can share with me? Or point me in a different direction if I'm off base here?

      Thanks,
      max
        • 1. Re: CFSELECT validation in Flash format form
          denvermax Level 1
          It's hard for me to believe I'm the only one who has had problems with CFFORM format="flash" cfselect validation. But hours of searching turned up VERY LITTLE. I managed to cobble something together, so for anyone else who has this problem, and happens across my post, here's how I solved it:

          <cfsavecontent variable="validate">

          // perform client side validation here if you want
          var validationError = "False";
          var myString = "Please Select a value for the following:";
          var alertTitle = "Data Input Required";
          if (theForm.testSelect.value == 'none')
          {
          var validationError = "True";
          var myString = myString + " Location,";
          }
          if (theForm.testSelect2.value == 'none')
          {
          var validationError = "True";
          var myString = myString + " Option2,";
          }
          if (validationError == 'True')
          {
          alert(myString,alertTitle);
          return false;
          }

          </cfsavecontent>

          <cfform name="theForm" action="" format="flash" height="220" width="450" onSubmit="#validate#">
          <cfselect name="testSelect" width="100" size="1" multiple="no" required="Yes" query="q1" display ="firstname" value ="firstname" selected="" queryPosition="Below">
          <option value="none">Select One
          </cfselect>
          <cfselect name="testSelect2" width="100" size="1" multiple="no" required="Yes" query="q1" display ="lastname" value ="lastname" selected="" queryPosition="Below">
          <option value="none">Select One
          </cfselect>
          <cfinput name="Location" type="text" label="Location" value="" width="300" required="Yes" message="Please provide a location" />
          <cfinput name="Test2" type="text" label="Test" value="" width="300" required="Yes" message="Please provide a test" />
          <cfinput type="submit" name="submitBtn" value="Send Data" width="100">
          </cfform>