Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Cfform validation

New Here ,
Apr 10, 2009 Apr 10, 2009

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?

2.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 06, 2009 Jun 06, 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>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 03, 2010 Apr 03, 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;}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 10, 2010 Apr 10, 2010
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources