Form Validation -- Newbie needs Help

M

Melissa

I am not sure if this is the right place for this or not. someone at
alt.html suggested I post this here.
I searched past posts in this newsgroup (and the web) but did not find
this specific problem, or a solution that I actually understood.
I am new to this - if wasn't already obvious, and I have been working
on this monster form and I cannot seem to get the reqired text
behavior to work correctly.


It is a request for samples. I want some of the info (name,address,
etc) to be required before the form will even submit.


I have assigned a behavior to the form tag to require certain info
from
the potential customer to be filled out. To cover all bases, I have
also
specified that the required fields be filled before it will send.
The code is below:


(note: some info has been changed to protect the innocent)


<form action="/cgi-bin/FormProcessor.pl" method="post"
name="SampleRequest" id="SampleRequest"
onSubmit="MM_validateForm('01)Name','','R','03)Title','','R'
,'04)Company
Name','','R','05)Address','','R','06)City','','R','07)State'
,'','R','08)Zip','','R','09)Phone','','R','12)Email','','R') ;return
document.MM_returnValue">
    <INPUT TYPE=HIDDEN NAME="admin" VALUE="(e-mail address removed)">
    <INPUT TYPE=HIDDEN NAME="subject" VALUE="Request For Samples">
    <INPUT TYPE=HIDDEN NAME="redirect"
VALUE="http://www.redirect.htm">
        <INPUT TYPE=HIDDEN NAME="required" VALUE="Name,Company
Name,Address,City, State,Zip,Telephone,Email">
..
..
..
</form>

This seems to work in every browser except IE 6 PC, naturally, it is
the browser used by nearly all of the company's customers.

If you hit the submit button in Firefox (or safari or opera)  without
typing something in the required fields, you get this pop up window :

Javascript
The following error(s) occurred:
- 01)Name is required.
- 02)Title is required.
- 04)Company Name is required.
- 05)Address is required.
- 06)City is required.
- 07)State is required.
- 08)Zip is required.
- 09)Phone is required.
- 12)Email is required.


Is there something special you have to do to get this to work in IE 6?

What am I not doing?
The area that is "onSubmit" was done in DWMX, the other "required"
stuff I put in by hand.
Is there something out of place?

Any insight is grreatly appreciated.

Thanks in advance,
Melissa
 
M

Matthew Lock

Melissa said:
<INPUT TYPE=HIDDEN NAME="admin" VALUE="(e-mail address removed)">

Do you know that if you put the admin email address in the form then
spammers will just create their own form that calls your server side
script and uses your server as a kind of relay? Read this:
http://www.rickconner.net/spamweb/spam_formmail.html

You want a server side script which has the admin email inside the
script on the server, not in a HTML form that anyone can change.
 
J

Jarmo

Melissa said:
<form action="/cgi-bin/FormProcessor.pl" method="post"
name="SampleRequest" id="SampleRequest"
onSubmit="MM_validateForm('01)Name','','R','03)Title','','R'
,'04)Company
Name','','R','05)Address','','R','06)City','','R','07)State'
,'','R','08)Zip','','R','09)Phone','','R','12)Email','','R') ;return
document.MM_returnValue">
<INPUT TYPE=HIDDEN NAME="admin" VALUE="(e-mail address removed)">
<INPUT TYPE=HIDDEN NAME="subject" VALUE="Request For Samples">
<INPUT TYPE=HIDDEN NAME="redirect"
VALUE="http://www.redirect.htm">
<INPUT TYPE=HIDDEN NAME="required" VALUE="Name,Company
Name,Address,City, State,Zip,Telephone,Email">
.
.
.
</form>

This seems to work in every browser except IE 6 PC, naturally, it is
the browser used by nearly all of the company's customers.

If you hit the submit button in Firefox (or safari or opera) without
typing something in the required fields, you get this pop up window :

Javascript
The following error(s) occurred:
- 01)Name is required.
- 02)Title is required.
- 04)Company Name is required.
- 05)Address is required.
- 06)City is required.
- 07)State is required.
- 08)Zip is required.
- 09)Phone is required.
- 12)Email is required.

Is there something special you have to do to get this to work in IE 6?

Form onsubmit validation works just fine in Explorer. Add a few alerts and
you'll soon find that either it's not calling your onsubmit handler or the
handler has a JavaScript error in which case it exits early and posts the
form (a super-annoying 'feature', if you ask me).

PS I think you're making life difficult for yourself though with the crazy
arguments to your MM_validateForm function.
 
R

RobG

Melissa wrote:
[...]
<form action="/cgi-bin/FormProcessor.pl" method="post"
name="SampleRequest" id="SampleRequest"
onSubmit="MM_validateForm('01)Name','','R','03)Title','','R' [...]
;return document.MM_returnValue">

Your error many be here. Try:

onSubmit="return MM_validateForm(....);"

MM_validateForm should return false if it fails or the script
detects an error in the input and programmatically returns
false.

As suggested by Jarmo, stick an alert in MM_validateForm just
before where you think it should terminate to see what values
various variables have. Alternatively use:

onSubmit="alert(MM_validateForm(....));"

to see what you are getting back.
 
R

RobB

Melissa said:
I am not sure if this is the right place for this or not. someone at
alt.html suggested I post this here.
I searched past posts in this newsgroup (and the web) but did not find
this specific problem, or a solution that I actually understood.
I am new to this - if wasn't already obvious, and I have been working
on this monster form and I cannot seem to get the reqired text
behavior to work correctly.


It is a request for samples. I want some of the info (name,address,
etc) to be required before the form will even submit.


I have assigned a behavior to the form tag to require certain info
from
the potential customer to be filled out. To cover all bases, I have
also
specified that the required fields be filled before it will send.
The code is below:


(note: some info has been changed to protect the innocent)


<form action="/cgi-bin/FormProcessor.pl" method="post"
name="SampleRequest" id="SampleRequest"
onSubmit="MM_validateForm('01)Name','','R','03)Title','','R'
,'04)Company
Name','','R','05)Address','','R','06)City','','R','07)State'
,'','R','08)Zip','','R','09)Phone','','R','12)Email','','R') ;return
document.MM_returnValue">
<INPUT TYPE=HIDDEN NAME="admin" VALUE="(e-mail address removed)">
<INPUT TYPE=HIDDEN NAME="subject" VALUE="Request For Samples">
<INPUT TYPE=HIDDEN NAME="redirect"
VALUE="http://www.redirect.htm">
<INPUT TYPE=HIDDEN NAME="required" VALUE="Name,Company
Name,Address,City, State,Zip,Telephone,Email">
.
.
.
</form>

This seems to work in every browser except IE 6 PC, naturally, it is
the browser used by nearly all of the company's customers.

If you hit the submit button in Firefox (or safari or opera) without
typing something in the required fields, you get this pop up window :
Javascript
The following error(s) occurred:
- 01)Name is required.
- 02)Title is required.
- 04)Company Name is required.
- 05)Address is required.
- 06)City is required.
- 07)State is required.
- 08)Zip is required.
- 09)Phone is required.
- 12)Email is required.


Is there something special you have to do to get this to work in IE 6?

What am I not doing?
The area that is "onSubmit" was done in DWMX, the other "required"
stuff I put in by hand.
Is there something out of place?

Any insight is grreatly appreciated.

Thanks in advance,
Melissa

Melissa - you've asked for help with a form validator, without posting
the validator itself, or any of the fields being validated. Everything
works together, so leaving out the pieces of the puzzle won't help you
get an answer.

I'll guess that your fields have names like...

<input type="text" name="01)Name"....>
<input type="text" name="03)Title"....>
<input type="text" name="04)Company Name"....>

That won't fly in Explorer, and in point of fact you should never name
any identifier (name, id, et al) with a leading numeric character. Try
it with the '0*)' removed. Don't forget to change the validator call as
well !
 
R

RobB

Melissa said:
So, are you saying that the MM_validateForm function does not need to be
there?

Change these:

<input type="text" name="01)Name"....>
<input type="text" name="03)Title"....>
<input type="text" name="04)Company Name"....>

....to these:

<input type="text" name="Name"....>
<input type="text" name="Title"....>
<input type="text" name="Company Name"....>

....and these:

onSubmit="MM_validateForm('01)Name','','R','03)Title','','R'
,'04)Company
Name','','R','05)Address','','R','06)City','','R','07)Stat.....

....to these:

onSubmit="MM_validateForm('Name','','R','Title','','R'
,'Company
Name','','R','Address','','R','City','','R','Stat.....

etc. If you want the error messages numbered consecutively, say so (&
post that function!).
 
R

RobB

Melissa said:
So, are you saying that the MM_validateForm function does not need to be
there?

Change these:

<input type="text" name="01)Name"....>
<input type="text" name="03)Title"....>
<input type="text" name="04)Company Name"....>

....to:

<input type="text" name="Name"....>
<input type="text" name="Title"....>
<input type="text" name="Company Name"....>

And these:

onSubmit="MM_validateForm('01)Name','','R','03)Title','','R'
,'04)Company
Name','','R','05)Address'......

to these:

onSubmit="MM_validateForm('Name','','R','Title','','R'
,'Company
Name','','R','Address'......

You're getting rid of that '03)' business, which appears to be
confusing MSIE's document.all accessor. If you want to number the
errors consecutively, that can be easily added to the existing code
(MM_validateForm) - but you'll have to post it as I'm not going to
waste the time searching for it again.
 
R

RobB

Melissa said:
OK, here is the script, with the fields that should be validated.
As for the lines being numbered, I did that because it seemed like it
controlled the appearance of the info that gets e-mailed to the
recipient --
there is a lot more to this form, it goes on to list thousands of
products that
have boxes to check, to indicate which samples you want.

Also, the previous form had numbers before the items, so I just left it
as is.
Could this be the problem to this whole thing?

Thank you all for taking the time to help me with this. I really
appreciated it.

Melissa

Melissa: Sorry about that second post, googlegroups is even more
ridiculous today then it usually is...

I detailed a possible solution. You must remove the ---> 03) <--- type
characters from *all* field names, and from the references to those
names in your
<form....onSubmit="MM_validateForm('--->01)<---Name','','R'....

Please try that and see what happens. Make a sample page with only a
few fields and see if it validates properly. You need to help out here.

Rob
 
R

RobG

Melissa wrote:
[...]
references in the <form....onSubmit="MM_validateForm.....
area
It validates and won't send without required info, but any field that is
not
numbered i.e: 01), does not show up on the email.
So basically, I get a blank e-mail even though the form fields have been
filled
out.

So MM_validateForm is processing the form and generating an
email? Does the output of the process use the client's email
program to send you the contents of the form?

You need to post the code to MM_validateForm - perhaps it is
expecting the removed characters as some component of its
processing.
 
R

RobB

Melissa wrote:

(snip)
I did not write any of this, Dreamweaver did. There may be some code in
other places that I have missed. (?)

The testing form, that I am using is here:
www.tomkt.com/testform1.htm

Thanks,
Melissa

Hi Melissa. Well - here's the issue: that MacroMedia validator function
MM_validateForm() uses another function MM_findObj() to 'find' each
form element that you specified in your <form onsubmit="..."> call.
Actually, MM_findObj is a one-size-fits-all function; it gets used for
the P7 (menu) scripting as well. Problem: it uses document.all - an IE
(& others) collection of all elements, accessible by name/id - to find
objects in that browser, and that won't work there if the item has a
name that begins with a digit, as "01)name" clearly does. Just as
obviously, your formmail needs that naming format to process the data.
You can use the document.getElementById() function to 'get' the field
(works, even though ids shouldn't begin with a digit either), but then
you lose IE4 users, if there are any still alive.

There are some 'clever' ways to script around this, but they will foul
things up for users with JS disabled. Maybe somebody has an idea...
 
R

RobB

Melissa wrote:

(snip)
I did not write any of this, Dreamweaver did. There may be some code in
other places that I have missed. (?)

The testing form, that I am using is here:
www.tomkt.com/testform1.htm

Thanks,
Melissa

OK. I don't know what the ethical considerations are in re modifying
Macromedia code for commercial use so, you're on your own legally.

Replace MM_validateForm() with this:

function MM_validateForm() { //v4.0
var
i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=args;
if (val) { nm=val.name.substring(val.name.indexOf(')')+1); if
((val=val.value)!="") {
if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an
e-mail address.\n';
} else if (test!='R') { num = parseFloat(val);
if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
min=test.substring(8,p); max=test.substring(p+1);
if (num<min || max<num) errors+='- '+nm+' must contain a
number between '+min+' and '+max+'.\n';
} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is
required.\n'; }
} if (errors) alert('The following error(s) occurred:\n'+errors);
document.MM_returnValue = (errors == '');
}

....and your <form> tag with:

<form action="/cgi-bin/FormProcessor.pl" method="post"
name="SampleRequest" id="SampleRequest"
onSubmit="e=this.elements;MM_validateForm(e[5],'','R',e[6],'','R',e[7],'','R',e[8],'','R',e[9],'','R',e[10],'','R',e[11],'','R',e[12],'','R',e[13],'','RisEmail');return
document.MM_returnValue">

I used the elements collection to get the elements involved, by integer
index (position). If you modify the first part of the form, you'll need
to adjust these. In the above, e.g., 'e[5]' refers to Form.elements[5],
the sixth - JS counts from zero - field in the form ("01)Name"). This
avoids referencing them by name. MM_validateForm() now takes a field
(object) reference, rather than a passing a field name to MM_findObj
(btw you've got *two* copies of that function there). The validator
also edits the field name for the alert, removing the "01)" part. Just
remove:

..substring(val.name.indexOf(')')+1)

....if you want to restore it. hth (nice site btw)
 
R

RobB

ps googlegroups totally butchered that post, shards of code everywhere.
See if you can figure it out (put everything on one line if necessary).
Sorry. /:-(
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top