Skip to main content
Participating Frequently
April 10, 2009
Question

Cfform validation

  • April 10, 2009
  • 1 reply
  • 2237 views

I have a cfform with regular expression validation. I was wondering if there is any way to not have the form submit when enter is hit. Currently it validates if you hit enter to go to the next form field.

Any ideas?

    This topic has been closed for replies.

    1 reply

    BKBK
    Community Expert
    Community Expert
    June 6, 2009

    To control whether or not to submit the form, use actionscript as the value of cfform's onSubmit attribute. If the last line of the script is return false, the form wont submit. An example follows

    <cfif isDefined('form.test')>
    <cfdump var="#form#">
    </cfif>


    <cfform method="post" format="flash" onsubmit="return submit_it()">
    <cfformitem type="script">
    function submit_it(){
        // to test, toggle between true and false
        return true;
    }
    </cfformitem>
    <cfinput type="submit" name="sbmt" value="Test it!">
    <cfinput type="text" name="test">
    </cfform>

    Participant
    April 4, 2010

    THANK YOU. I'm trying to figure this out for last 3 hour, onSubmit and Actionscript.

    But ow can i check it against regular expression?

    Please help me correct the following code:

    var y = "[A-Z]{1,3}"
        var x = check1.text

    if(!(x.match(y))){

         return false;}

    else

         { return true;}

    BKBK
    Community Expert
    Community Expert
    April 10, 2010

    sunny_2010 wrote:

    THANK YOU. I'm trying to figure this out for last 3 hour, onSubmit and Actionscript.

    But ow can i check it against regular expression?

    Please help me correct the following code:

    var y = "[A-Z]{1,3}"
        var x = check1.text

    if(!(x.match(y))){

         return false;}

    else

         { return true;}

    This is Actionscrionscript, but is unrelated. You should have started your own thread.

    In any case, you could easily look up the usage of match() on the web.  You will find that

    1) it takes a RegExp pattern as parameter;

    2) it returns an array, not a boolean

    Your if-statement could therefore test for array length instead. The same link gives you documentation on the search() method. It returns an integer, and so is simpler to use in testing a match.