htmlArea

A directory of browser-based WYSIWYG editors

  MAIN
INDEX
SEARCH
POSTS
WHO'S
ONLINE
LOG
IN

Home: htmlArea 3 (beta): htmlArea 2 & 3 archive (read only): htmlArea v3.0 - Discussion:
Help - Validating Other Form Fields?


The htmlArea 2 & 3 editors have been discontinued.

We've made these forums available as a read-only reference and knowledge-base for people using or developing editors based on htmlArea 2 or 3.

Anyone who is interested in taking over version 2 or 3 is free to do so. All we ask is that you choose a new name that doesn't have "htmlarea" in it to avoid confusion with this site. We'll even give you a link in the directory to make it easier for people to find you. If you are developing or hosting an htmlArea based-editor under a new name, please submit it to our directory.

 


BubbaGump01
New User

Apr 23, 2004, 12:04 PM

Post #1 of 22 (7480 views)
Shortcut
Help - Validating Other Form Fields? Can't Post

Hello all…



I am trying to get some type of form validation to work on my page with HTMLArea v3. I have been able to validate the HTMLArea its self using some helpful threads on this forum. But I really don’t need to validate the Text area but rather other form fields that I have on the same page. I have tried various methods and none have worked… it seems to just ignore the validation and submit the form.



Could someone give me some ideas on what to do here… all I need to do is validate a “First Name”, “Last Name” and State fields?



Thanks a ton…


BubbaGump01
New User

Apr 26, 2004, 9:28 AM

Post #2 of 22 (7440 views)
Shortcut
Re: [BubbaGump01] Help - Validating Other Form Fields? [In reply to] Can't Post

any ideas here... ?

I am having a hard time getting any other JavaScript to work on the same page as the HtmlArea...

Thanks...


howardf
Novice

Apr 26, 2004, 7:32 PM

Post #3 of 22 (7435 views)
Shortcut
Re: [BubbaGump01] Help - Validating Other Form Fields? [In reply to] Can't Post

Altering any of the the example marginally, change the submit button code something like this


Code
 <input type="button" name="ok" value="  submit  " onClick ="javascript:mySubmit()"/> 

<script type="text/javascript">
function mySubmit() {
//document.edit.save.value = "yes";

<!--Validation stuff here ( if criteria not met then alert("Frown") and return)
else -->

document.edit.onsubmit(); // workaround browser bugs.
document.edit.submit();
};
</script>



mrkshrt
New User

Apr 28, 2004, 2:05 PM

Post #4 of 22 (7412 views)
Shortcut
Re: [howardf] Help - Validating Other Form Fields? [In reply to] Can't Post

How do you handle the problem of someone just pressing Enter key instead of clicking on a button or link?

Mark


rwolman
New User

Jun 7, 2004, 7:00 AM

Post #5 of 22 (7287 views)
Shortcut
Re: [BubbaGump01] Help - Validating Other Form Fields? [In reply to] Can't Post

I also spent a lot of time yesterday with this form validation onSubmit issue. This morning the fog must have cleared as I figured out how to make my validation routine work as it should.

Normally, a form will have an onSubmit with something like this: onSubmit="return validateForm(this)". It never seemed to validate when I had HTMLarea 3.0 rc1 in it. I made the following changes to the htmlarea.js file to fix this problem (thanks to another poster for the unshift versus push fix):

if (textarea.form) {
// we have a form, on submit get the HTMLArea content and
// update original textarea.
var f = textarea.form;
if (typeof f.onsubmit == "function") {
var funcref = f.onsubmit;
if (typeof f.__msh_prevOnSubmit == "undefined") {
f.__msh_prevOnSubmit = [];
}
f.__msh_prevOnSubmit.unshift(funcref);
}
f.onsubmit = function() {
editor._textArea.value = editor.getHTML();
var a = this.__msh_prevOnSubmit;
// call previous submit methods if they were there.
if (typeof a != "undefined") {
for (var i in a) {
rtn = a();
if (!rtn)
{
return false;
}
}
}
};
}


The two changes are:

instead of f.__msh_prevOnSubmit.push(funcref) you use f.__msh_prevOnSubmit.unshift(funcref)

and

instead of a() you use:

rtn = a();
if (!rtn)
{
return false;
}

I hope this helps.

Cheers,
rcw


mcoder
Novice

Jun 7, 2004, 7:40 AM

Post #6 of 22 (7285 views)
Shortcut
Re: [rwolman] Help - Validating Other Form Fields? [In reply to] Can't Post


In Reply To
for (var i in a) {
rtn = a();
if (!rtn)
{
return false;
}
}
}
};
}



The fix is not correct.

Replace this code with:

for (var i in a)
{
if (!a()) return 0;
}
return 1;

This way, all the other submits are correctly tested (and not the only one in your fix).

About the unshift, I didn't apply such a trick, but encountered no problem...


drsirius
Novice

Nov 3, 2004, 1:44 AM

Post #7 of 22 (6921 views)
Shortcut
Re: [mcoder] Help - Validating Other Form Fields? [In reply to] Can't Post

I have applied these changes but I am still struggling with this.Blush


mcoder
Novice

Nov 3, 2004, 2:29 AM

Post #8 of 22 (6914 views)
Shortcut
Re: [drsirius] Help - Validating Other Form Fields? [In reply to] Can't Post

Yes, I did a mistake. Try this version, it works fine here (both on Mac and PC):

f.onsubmit = function() {
editor._textArea.value = editor.getHTML();
var a = this.__msh_prevOnSubmit;
// call previous submit methods if they were there.
if (typeof a != "undefined") {
for (var i = a.length; --i >= 0;) {
if (!a()) return 0;
}
}
return 1;
};


drsirius
Novice

Nov 3, 2004, 2:38 AM

Post #9 of 22 (6908 views)
Shortcut
Re: [mcoder] Help - Validating Other Form Fields? [In reply to] Can't Post

Could you please post the complete section of that code for the function. javascript is not really my forté and I am struggling to get it to work. Blush


mcoder
Novice

Nov 3, 2004, 2:42 AM

Post #10 of 22 (6905 views)
Shortcut
Re: [drsirius] Help - Validating Other Form Fields? [In reply to] Can't Post

Just get the latest version of HTMLArea, and replace the code of f.onsubmit.

Simply copy/paste my version, and all will work fine.


drsirius
Novice

Nov 3, 2004, 2:53 AM

Post #11 of 22 (6902 views)
Shortcut
Re: [mcoder] Help - Validating Other Form Fields? [In reply to] Can't Post

I have done this but am still struggling. Crazy


drsirius
Novice

Nov 3, 2004, 3:02 AM

Post #12 of 22 (6898 views)
Shortcut
Re: [mcoder] Help - Validating Other Form Fields? [In reply to] Can't Post

The validation code I am running is:

Code
 <script Language="JavaScript"> 
<!--
function MessageValidate(theForm)
{

if (theForm.Subject.value == "")
{
alert("Please enter a subject title for your message.");
theForm.Subject.focus();
return (false);
}

if (theForm.Message.value == "")
{
alert("Please enter a message.");
theForm.Message.focus();
return (false);
}

return (true);
}
//-->
</script>


With the Button code being:

Code
<input type="submit" value="Post New Message"  name="cmdSubmit" class="vdx">


Should this work?


mcoder
Novice

Nov 3, 2004, 3:23 AM

Post #13 of 22 (6891 views)
Shortcut
Re: [drsirius] Help - Validating Other Form Fields? [In reply to] Can't Post

I'm curious, how is called MessageValidate ?

I personally use:
<a class="valider" href="#" onclick="return checkemailing();">Valider</a>

And all the INPUTs and the TEXTAREA are in a form.


drsirius
Novice

Nov 3, 2004, 3:26 AM

Post #14 of 22 (6887 views)
Shortcut
Re: [mcoder] Help - Validating Other Form Fields? [In reply to] Can't Post

In the form by default:

Code
<FORM ACTION="message.cfm" METHOD="Post" onsubmit="return MessageValidate(this)">



mcoder
Novice

Nov 3, 2004, 3:29 AM

Post #15 of 22 (6886 views)
Shortcut
Re: [drsirius] Help - Validating Other Form Fields? [In reply to] Can't Post

Do you have an online test page ?


drsirius
Novice

Nov 3, 2004, 3:43 AM

Post #16 of 22 (6883 views)
Shortcut
Re: [mcoder] Help - Validating Other Form Fields? [In reply to] Can't Post

 

http://www.peresoft.com/fnewtest.cfm With HtmlArea 3.0
http://www.peresoft.com/fnewtest1.cfm Without HtmlArea 3.0


mcoder
Novice

Nov 3, 2004, 3:55 AM

Post #17 of 22 (6881 views)
Shortcut
Re: [drsirius] Help - Validating Other Form Fields? [In reply to] Can't Post

Ok, you have a Javascript error on IE Windows.

Activate the JS errors on IE to get it.


drsirius
Novice

Nov 3, 2004, 4:12 AM

Post #18 of 22 (6875 views)
Shortcut
Re: [mcoder] Help - Validating Other Form Fields? [In reply to] Can't Post

It reports "a is not a function" in:

Code
 f.onsubmit = function() { 
editor._textArea.value = editor.getHTML();
var a = this.__msh_prevOnSubmit;
// call previous submit methods if they were there.
if (typeof a != "undefined") {
for (var i = a.length; --i >= 0;) {
if (!a()) return 0;
}
}
return 1;
};



mcoder
Novice

Nov 3, 2004, 4:23 AM

Post #19 of 22 (6869 views)
Shortcut
Re: [drsirius] Help - Validating Other Form Fields? [In reply to] Can't Post

Ok, the editor truncated the code:

f.onsubmit = function() {
editor._textArea.value = editor.getHTML();
var a = this.__msh_prevOnSubmit;
// call previous submit methods if they were there.
if (typeof a != "undefined") {
for (var i = a.length; --i >= 0;) {
if (!a[i]()) return 0;
}
}
return 1;
};


drsirius
Novice

Nov 3, 2004, 4:53 AM

Post #20 of 22 (6861 views)
Shortcut
Re: [mcoder] Help - Validating Other Form Fields? [In reply to] Can't Post

Thanks for that...however...Frown...

The validation now works but the form still submits afterwards.


mcoder
Novice

Nov 3, 2004, 5:09 AM

Post #21 of 22 (6854 views)
Shortcut
Re: [drsirius] Help - Validating Other Form Fields? [In reply to] Can't Post

Try to put some alert('message'); before the return(s).

This way, you'll see where the code passes.


sceilig
New User

Nov 10, 2004, 4:01 AM

Post #22 of 22 (6746 views)
Shortcut
Re: [mcoder] Help - Validating Other Form Fields? [In reply to] Can't Post

I tried the above fix and it didnt work for me either. My form validation would kick in, but the form would still submit even if one of my form fields was empty.

Found this patch and it worked for me
http://odb.mokhet.com/htmlarea/cvs167-patch.html.
(the lines highlighted in green on the right are the ones to insert into your f.onsubmit function.


 
 
 


Search for (options)