Sagewire Logo

JAVAscript validation in CF

4 Message(s) by 2 Author(s) originally posted in cold fusion


From: ll Date:   Friday, April 27, 2007
Hi,
I am working with a page that has both CFFORM elements and 'plain
html' form elements. In particular, I am needing to validate my
text area form field and my email text field. On one of my html pages,
I have been using a great JAVAscript validation script; however, I am
wondering if I can use that in a Cold Fusion page? I have include d the
JAVAscript I'd been using before.
Thanks for any help you can provide,
Regards,
Louis

In the CFFORM tag, I included this call:
<CFFORM action="#cgi.script_name#" method="Post" name="NewItemForm"
onSubmit="return checkWholeForm(this)" >


The JAVAscript in the head is listed below:
-----
<script language="JAVAScript">
// news headline/email subject
function checkEmailSubject (strng) {
var error ="";
if (strng == "") {
error = "Please enter an Email Subject/News Headline.\n\n";

}

// news/email content
function checkContent (strng) {
var error="";
if (strng == "") {
error = "Please enter Email/News Content.\n\n";

}

// email
function checkEmail (strng) {
var error="";
if (strng == "") {
error = "Please enter your email address .\n\n";

}

//filter for ou/ouhsc domain s
var emailFilter2=/.@xxxxxxxxxxx(ou|ouhsc)\.edu$/i
if (!(emailFilter2.test(strng))) {
error="Please enter a valid email address with either ou or ouhsc
domain.\n\n";
}
//end domain filter

var emailFilter=/^.+@xxxxxxxxxxx+\..{2,3}$/;
if (!(emailFilter.test(strng))) {
error = "Please enter a valid email address.\n\n";
}
else {
//test email for illegal characters
var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
if (strng.match(illegalChars)) {
error = "The email address contains illegal characters.\n
\n";
}

}
return error;

}

<!-- Begin check form script, which refers to above -->

function checkWholeForm(NewItemForm) {
var why = "";
why += checkEmail(NewItemForm.Email1.value);
why += checkEmailSubject(NewItemForm.EmailSubject.value);
why += checkContent(NewItemForm.Content.value);
if (why != "") {
alert(why);
return false;
}
return true;
}

// -->
</script>
<!-- End form validation script -->


From: ll Date:   Friday, April 27, 2007
wrote in message:
wrote in message:
> I am working with a page that has both CFFORM elements and 'plain
> html' form elements. In particular, I am needing to validate my
> textarea form field and my email text field. On one of my html pages,
> I have been using a great JAVAscript validation script; however, I am
> wondering if I can use that in a Cold Fusion page? I have included the
> JAVAscript I'd been using before.
JAVAScript is a client-side technology and does not have anything
to do with Cold Fusion. You will need to include separate validation
code written in CFML of CFScript.
--
Bob Dively | I used to be indecisive, but now I'm not sure...



Thanks,
However, JAVAscript is used quite commonly with CFML (
http://Cold Fusion.sys-con.com/read/41954.htm ). I have been trying to
get the approach on this page to work, as well, with little success.
Has anyone done this on their site?

Thanks,
Louis


From: Bob Dively Date:   Friday, April 27, 2007
wrote in message:

I am working with a page that has both CFFORM elements and 'plain
html' form elements. In particular, I am needing to validate my
textarea form field and my email text field. On one of my html pages,
I have been using a great JAVAscript validation script; however, I am
wondering if I can use that in a Cold Fusion page? I have included the
JAVAscript I'd been using before.



JavaScript is a client-side technology and does not have anything
to do with Cold Fusion. You will need to include separate validation
code written in CFML of CFScript.

--
Bob Dively | I used to be indecisive, but now I'm not sure...


From: Bob Dively Date:   Friday, April 27, 2007
wrote in message:

However, JAVAscript is used quite commonly with CFML (
http://Cold Fusion.sys-con.com/read/41954.htm ). I have been trying to
get the approach on this page to work, as well, with little success.
Has anyone done this on their site?



Ok, I see what you mean now. JAVAScript is commonly used on pages
generate d *by* Cold Fusion. With regard to CFML, JAVAScript is
just a bunch of text that's not interpreted by Cold Fusion. CFFORM
tags generate JAVAScript that's included with the rest of the
page being generated. You can write additional JAVAScript that
hooks into the JAVAScript generated by CFFORM, as detailed in the
link you posted. So, the answer to your question is, yes, there's
no reason you can not do that.

--
Bob Dively | I used to be indecisive, but now I'm not sure...



Next Message: Cold Fusion 8


Blogs related to JAVAscript validation in CF

RE: Client-side validation or Server-side Validation?
Rick, > Do you use Ajax to pass data from the form to CF for validation, > then return the results to the form page? 95+% of the time, No, I personally do not use Ajax as part of my form validation. When I build an app, ...

Client-side validation or Server-side Validation?
>>Does the JS and CF validation have to be totally independent in functionality? Basically yes ;-) I mean: 1ยบ Javascript is so useful for so many things, I simply won't let a user fill a form if they have Javascript disable, period. ...

RE: Client-side validation or Server-side Validation?
>But now that I've started down the client-side validation road, I hear >from passersby, "No! You should always validate server-side or both!" > >(I did experiment with jQuery to use Ajax to validate server-side with CF, >but couldn't ...

JavaScript Browser Support History
the form validation functions are completely generated by a framework. So the normal methods of feature checking don't work in this case. I found my answer on the Mozilla Web site. ...

How to turn this into a REGEX for use in javascript?
I've been tinkering with validation using js and would like to know how to turn this into a regex for use in js: Is Numeric (REReplace(Form.Sale_Price, "[.$,]","","All")) Any help available? Thanks, ...

Re: Client-side validation or Server-side Validation?
We could develop a language for expressing validation generally and write tools that produce validation code in javascript, php, ColdFusion, ActionScript, etc. for us and not feel that we have to choose one or the other. ...


Programming | Sports | Autos

copyright 2006
Valid XHTML 1.0 Transitional