Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Why doesn't OnSubmit validation work for text fields on my record edit page?

Posted on 2011-09-15
13
Medium Priority
?
394 Views
Last Modified: 2012-06-27
I'm been puzzling over this for a while. Why doesn't OnSubmit validation work for text fields on my record edit page? For example:

Email Address: <cfinput type="text" name="UserEmail" value="#form.UserEmail#" validate="email" required="Yes" validateAt="onSubmit,onServer" message="Please enter a valid email address." size="35" tabindex="8" />
       
If I enter no value in the text field, then I see the error message in OnServer validation, which is less friendly and more forbidding than the friendly pop-up alert window of onSubmit validation.

When I view the source of the edit page, I see the ColdFusion-built script that creates the onSubmit alert window:

<script type="text/javascript">/* <![CDATA[ */
	if (window.ColdFusion) ColdFusion.required['firstname']=true;
/* ]]> */</script>

<script type="text/javascript">/* <![CDATA[ */
	if (window.ColdFusion) ColdFusion.required['UserEmail']=true;
/* ]]> */</script>
<script type="text/javascript">
<!--
    _CF_checkCFForm_1 = function(_CF_this)
    {
        //reset on submit
        _CF_error_exists = false;
        _CF_error_messages = new Array();
        _CF_error_fields = new Object();
        _CF_FirstErrorField = null;

        //form element firstname required check
        if( !_CF_hasValue(_CF_this['firstname'], "TEXT", false ) )
        {
            _CF_onError(_CF_this, "firstname", _CF_this['firstname'].value, "Please enter your first name.");
            _CF_error_exists = true;
        }

        //form element UserEmail required check
        if( !_CF_hasValue(_CF_this['UserEmail'], "TEXT", false ) )
        {
            _CF_onError(_CF_this, "UserEmail", _CF_this['UserEmail'].value, "Please enter a valid email address.");
            _CF_error_exists = true;
        }


        //display error messages and return success
        if( _CF_error_exists )
        {
            if( _CF_error_messages.length > 0 )
            {
                // show alert() message
                _CF_onErrorAlert(_CF_error_messages);
                // set focus to first form error, if the field supports js focus().
                if( _CF_this[_CF_FirstErrorField].type == "text" )
                { _CF_this[_CF_FirstErrorField].focus(); }

            }
            return false;
        }else {
            return true;
        }
    }
//-->
</script>

Open in new window


However, the onSubmit alert window does not appear. I've read the documentation and think I am doing things correctly:
http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec0ffd8-7fea.html

What am I missing? Thank you as always.

Eric
0
Comment
Question by:Eric Bourland
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
  • 2
13 Comments
 
LVL 63

Expert Comment

by:Zvonko
ID: 36541579
Use preservedata like this:
<cfform name="myform" preservedata="Yes" > 

Open in new window

And remove that part form your input field:
<cfinput type="text" name="UserEmail"  validate="email" required="Yes" validateAt="onSubmit,onServer" message="Please enter a valid email address." size="35" tabindex="8" />

Open in new window

0
 
LVL 3

Author Comment

by:Eric Bourland
ID: 36541612
>>>And remove that part form your input field:

<cfinput type="text" name="UserEmail"  validate="email" required="Yes" validateAt="onSubmit,onServer" message="Please enter a valid email address." size="35" tabindex="8" />

Which part of the input field should I remove?

I will try the preservedata attribute ... thank you!

Eric
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 36541726
The part that should preserve the field value:
value="#form.UserEmail#" 

Open in new window

In my test was that the error part that is obsolate when you use the cfform attribute.
0
Give Your Engineering Team a Productivity Boost

Learn why container technology is so powerful and how it can provide your team with productivity gains and other benefits.

 
LVL 52

Expert Comment

by:_agx_
ID: 36542657
>> Why doesn't OnSubmit validation work for text fields on my record edit page?

What you posted works fine.   There must be something else going on.

<cfparam name="form.UserEmail" default="">
<cfform name="x" method="post">
<cfinput type="text" name="UserEmail" value="#form.UserEmail#" validate="email" required="Yes" validateAt="onSubmit,onServer" message="Please enter a valid email address." size="35" tabindex="8" />
<input type="submit">
</cfform>
0
 
LVL 3

Author Comment

by:Eric Bourland
ID: 36544505
You're right, there is something else going on.

The form processes, and populates correctly the parent table CareplannersMembers and five relational tables. For an experiment, I took away the onServer validation:

validateAt="onSubmit"

Then I cleared the field for #UserEmail# -- I mean, I entered no email address in the cfinput text field -- and processed the form; the form gave me an error:

Attribute validation error for CFMAIL. 
The value of the FROM attribute is invalid. The length of the string, 0 character(s), must be greater than or equal to 1 character(s). 
 The error occurred in C:/websites/www.osm-vista.com/admin/userEdit.cfm: line 418
Called from C:/websites/www.osm-vista.com/admin/userEdit.cfm: line 253
Called from C:/websites/www.osm-vista.com/admin/userEdit.cfm: line 232
Called from C:/websites/www.osm-vista.com/admin/userEdit.cfm: line 226
Called from C:/websites/www.osm-vista.com/admin/userEdit.cfm: line 1
416 :    <cfmail  
417 :       server="mail.careplanners.net"  
418 :       from="#form.UserEmail#" 
419 :       to="STServ@careplanners.net" 
420 :       subject=""  

Open in new window


This means that, when I enter no email address in the Email address field, the form does not generate a value for #UserEmail#, even though I have set:
<cfparam name="form.UserEmail" default="">

I am looking for reasons why the form does not generate a value for #UserEmail#. Hmm.
0
 
LVL 52

Expert Comment

by:_agx_
ID: 36544582
>> the form does not generate a value for #UserEmail#

No, the error message says it does have a value, but it's an empty string which isn't a valid email address.

If only the onSubmit validation isn't working - you're looking for javascript errors.  Use Firefox's error console or the Firebug  plugin.
0
 
LVL 3

Author Comment

by:Eric Bourland
ID: 36544686
That makes sense. I'm on it.
0
 
LVL 3

Author Comment

by:Eric Bourland
ID: 36547007
Hmmm. Firebug reports all clear. And when I view page source, and copy that source into Dreamweaver CS 5, I get no reports of javascript errors. DW CS5 is usually pretty robust about reporting script errors.

I am trying a few other ideas. The form works perfectly otherwise, with the exception of the onSubmit. I'm gonna take a walk and think about it. I'll come back later.

Thank you again _agx_ and Zvonko.

Eric
0
 
LVL 52

Expert Comment

by:_agx_
ID: 36549571
>> with the exception of the onSubmit.

For just that one field or for all onSubmit validation?
0
 
LVL 3

Author Comment

by:Eric Bourland
ID: 36550311
All onSubmit validation on all fields does not work. Which is a clue I have been thinking about.
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 2000 total points
ID: 36550659
Oh, sorry I didn't realize it was all fields.  Then it's probably a different issue. Since you're not seeing any errors, maybe it's the usual mapping problem with /CFIDE . Or maybe jquery problems?
0
 
LVL 3

Author Comment

by:Eric Bourland
ID: 36550675
Ugh. Mapping to CFIDE. Of course. Hang on....
0
 
LVL 3

Author Closing Comment

by:Eric Bourland
ID: 36550842
Forgot to map to /CFIDE/ in new web site. I need to get more sleep....

Thank you _agx_ and Zvonko.
0

Featured Post

Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for subm…
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question