Google Answers Logo
View Question
 
Q: FrontPage's validation problem (easy question) ( Answered 5 out of 5 stars,   0 Comments )
Question  
Subject: FrontPage's validation problem (easy question)
Category: Computers > Internet
Asked by: amirehsans-ga
List Price: $2.00
Posted: 09 Jun 2003 00:03 PDT
Expires: 09 Jul 2003 00:03 PDT
Question ID: 214965
Hi. I have made a form in FP2002. I used FP's nice interface for
validating fields (in Field Properties). I also made a confirmation
page, and I uploaded my file onto the Internet.  Everything worked
fine.

Then, I wanted to add a few other validation criteria, by writing a
small Javascript in the head; a function called validate().  And you
know how you put a onSubmit="validate();" tag in your form properties.
So I did that.  BUT the funny thing is, when I published the pages
this time, the generated code (I looked up by View Source) does not
include my call to validate(), rather, it has FP's generated clause:
onSubmit="return FrontPage_Form1_Validator(this)"

So, I'm totally clueless as of how to tell FP to first run my own
method, and then its own validation stuff.  It seems to overwrite my
onSubmit. Please help me out. Thanks!

Request for Question Clarification by errol-ga on 09 Jun 2003 05:39 PDT
Hi there!

I also have Frontpage 2002 on my system.
Try doing the following and let me know if it works so I can post it
as an answer.

- Go to the Insert menu, then select Web Component.
- Select Advanced Controls then HTML at the top right.
- In this text box you can insert HTML code that will not be modified
by Frontpage so view source on the entire form code that you already
have and paste it into this text area, adding your own javascript
code.

Hope this helps,
errol-ga.

Clarification of Question by amirehsans-ga on 09 Jun 2003 10:58 PDT
Well, actually I tried what you said, but this FP is so stubborn, that
when I add my own HTML the way you said, and then try to publish, it
digests my HTML and rewrites it the way I told you in my first
writing. Is there any other way around this?

I actually tried putting a onClick="validate();" in my Submit button.
What happens is that the script is run, but the confirmation page is
automatically loaded at the same time that the visitor receives the
alert. This way, my JS validation sounds reduntant because the user
doesn't get to correct their mistakes.

So how can I change my validate so that if the criteria fail, then my
form's action=... is not run?

(if you know another/a better solution please tell me)

Thank you.

Request for Question Clarification by errol-ga on 09 Jun 2003 11:19 PDT
Hello again, if possible could you paste the script into here so I can
change it for you?
You could try using this: [ onClick="validate(); return false;" ] but
I can't guarantee that it will work without seeing the validation
script.

Regards,
errol-ga.

Clarification of Question by amirehsans-ga on 09 Jun 2003 15:05 PDT
Hi, and thanks so much for trying to help me out.

I tried what you said, (put that return false; thing after validate();
in my submit button properties. What happened is that the JS
validation would tell you if you're wrong, but if nothing is wrong
with JS validation, nothing will happen and your FP validation doesn't
run, and you won't be forwarded to the confirmation page.

The original script that I was telling you about and makes 100% sense
to me is as follows.  Actually, here is my own validation script in
the <head>:

<script language="JavaScript" type="text/javascript">

	function validate(){
		if (window.FrontPage_Form1.T1.value.length>5){
			window.alert('why more than 5?');
			return false;
		}
	return true;
	}
</script>

And my form HTML is: (I've just added the validate(); to onSubmit,
everything else is generated by FP) I've also lined up the properties
so they're easier for you to read :-)

-------------------------------------------------------

<form method="POST" 
action="--WEBBOT-SELF--" 
onSubmit="validate(); return FrontPage_Form1_Validator(this)"
name="FrontPage_Form1"
language="JavaScript">

<!--webbot bot="SaveResults" 
s-email-format="TEXT/PRE" 
b-email-label-fields="TRUE" 
s-builtin-fields 
u-confirmation-url="conf_test.htm" 
s-email-address="amirehsans@yahoo.com" 
startspan -->

<input TYPE="hidden" NAME="VTI-GROUP" VALUE="0">

<!--webbot bot="SaveResults" endspan 
i-checksum="43374" --><p>

  Please enter your name here:&nbsp;

<!--webbot bot="Validation" 
s-data-type="String" 
b-allow-letters="TRUE" 
b-allow-whitespace="TRUE" -->

<input type="text" 
name="T1" size="20"></p>

<p><input type="submit" value="Submit" name="B1">

<input type="reset" value="Reset" name="B2"></p>
</form>

-------------------------------------------------------
After I publish, here is the page that results:
www.magicaloffers.com/test_form.htm

I've set the confirmation page (thru FP's form properties window) to
be
www.magicaloffers.com/conf_test.htm
-------------------------------------------------------

If you look at the source of the published
www.magicaloffers.com/test_form.htm, this is what you'll see:

of course, you'll still see my validate() up there, but the parts that
are generated/different are:


--------------------------------------------------------------
<body>
<p>
<!--webbot BOT="GeneratedScript" PREVIEW=" " startspan --><script
Language="JavaScript" Type="text/javascript"><!--
function FrontPage_Form1_Validator(theForm)
{

  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ
\t\r\n\f";
  var checkStr = theForm.T1.value;
  var allValid = true;
  var validGroups = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only letter and whitespace characters in the
\"T1\" field.");
    theForm.T1.focus();
    return (false);
  }
  return (true);
}
//--></script>

<!--webbot BOT="GeneratedScript" 
endspan -->

<form method="POST" 
action="_vti_bin/shtml.exe/test_form.htm" 
onSubmit="return FrontPage_Form1_Validator(this)" 
name="FrontPage_Form1" 
language="JavaScript" 
webbot-action="--WEBBOT-SELF--">

  <!--webbot bot="SaveResults" 
s-email-format="TEXT/PRE" 
b-email-label-fields="TRUE" s-builtin-fields 
u-confirmation-url="conf_test.htm" 
s-email-address="amirehsans@yahoo.com" 
startspan -->

<input TYPE="hidden" NAME="VTI-GROUP" VALUE="0"><!--webbot
bot="SaveResults" endspan i-checksum="43374" --><p>

  Please enter your name here:&nbsp;

  <!--webbot bot="Validation" 
s-data-type="String" 
b-allow-letters="TRUE" 
b-allow-whitespace="TRUE" -->

<input type="text" name="T1" size="20"></p>

  <p><input type="submit" value="Submit" name="B1"><input type="reset"
value="Reset" name="B2"></p>
</form>

---------------------------------------------------

And, as you can see, the generated/published HTML ignores my
validate() call and only runs FP's own.

I would really appreciate your help, and thank for taking the time to
answer my question.

Clarification of Question by amirehsans-ga on 09 Jun 2003 18:19 PDT
I just wanted to add that I value the time you're spending on my
question, and will definitely tip you when you answer me.  I just
won't increase the fee because another researcher might answer the
question and your efforts will be diminished.
Answer  
Subject: Re: FrontPage's validation problem (easy question)
Answered By: errol-ga on 10 Jun 2003 06:31 PDT
Rated:5 out of 5 stars
 
Hello again!

It's not Frontpage that is causing this, it's because the code doesn't
actually work anyway.
The script that you wrote makes perfect sense when you look at it, it
*should* work but this is Javascript we're dealing with. :)
The following altered code has been tested in Mozilla 1.4 and Internet
Explorer 6:

<script language="JavaScript" type="text/javascript"> 
 function validate(form) { 
  if (document.FrontPage_Form1.T1.value.length>5)
{ 
   window.alert('why more than 5?'); 
	return false;
  } 
return true;
 } 
</script>

Then, you need to change your Submit button code to this:

<input type="submit" onClick="javascript:return validate(this);"
value="Submit">

Simply switch to the HTML view in Frontpage and paste the OnClick part
into the submit button code and the altered script into the <head> of
the document.

I hope this helps!
Kind regards,
errol-ga.

Request for Answer Clarification by amirehsans-ga on 10 Jun 2003 12:15 PDT
Hey error-ga, first thanks to your great answer.  It works perfectly!

Just wanted to ask something which probably isn't worth the minimum
cost of $2.50, but I would really appreciate it if you could answer:

What can I add to the HTML code of a page, if I want the window
opening it to be in focus.  That is, if you open a window through a
link, it wouldn't be buried under the pile of other open browser
windows?

Thanks again. God bless you.

Clarification of Answer by errol-ga on 10 Jun 2003 15:50 PDT
Hi there!
Many thanks for your kind rating and tip!

To focus a window that you are opening, use code like this:
var w = window.open("", "RunWindow");
w.focus();

So, in a function:

<head>
<script type="text/javascript" language="javascript">
function openfocuswindow()
{
var w = window.open("", "RunWindow");
w.focus();
}
</script>
</head>

Then, call it like this:
<a href="#" onClick="openfocuswindow();">Link</a>

errol-ga.
amirehsans-ga rated this answer:5 out of 5 stars and gave an additional tip of: $3.00
error-ga is a great guy. He really took the time to see what was wrong
with my code, and I really appreciate his help. Also thanks to google
for not limiting this service to "research", but also this type of
help (debugging, analysis) too!

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy