form validation then action

D

dougawells

I'm not figuring this probably simple thing out.

I've got a form that when submitted takes an action to a Perl
script..."...formsubmit.pl".

I want to be able to validate some fields, so put an onSubmit fall in
the <form> tag. Problem is, that if the form validates fine, the action
never takes place.

What am i missing?
 
V

VK

I'm not figuring this probably simple thing out.

I've got a form that when submitted takes an action to a Perl
script..."...formsubmit.pl".

I want to be able to validate some fields, so put an onSubmit fall in
the <form> tag. Problem is, that if the form validates fine, the action
never takes place.

What am i missing?

To return true from onsubmit handler.
<form action="foo.cgi" onsubmit="return validate(this)">
where function validate returns either true or false.
 
D

dougawells

That's what i thought, but it doesn't seem to be working. I have the
<form onSubmit="return formValidate();" action="sendmyform.pl">

function formValidate() {

if (field is empty) {alert & then send focus to field in question}

}

This works if I have a problem field - I get an alert and return focus
to that field. But, I never execute the CGI, no matter what. I tried
return (true). I tried return; ...

??
 
L

Lee

(e-mail address removed) said:
That's what i thought, but it doesn't seem to be working. I have the
<form onSubmit="return formValidate();" action="sendmyform.pl">

function formValidate() {

if (field is empty) {alert & then send focus to field in question}

}

This works if I have a problem field - I get an alert and return focus
to that field. But, I never execute the CGI, no matter what. I tried
return (true). I tried return; ...

??

Post a link to your page or the smallest subset of the code that
demonstrates the problem. You've got an error somewhere.


--
 
D

dougawells

This is my form validation subroutine:

function validateForm() {

if (window.document.ticket_form.name.value == 0 ||
window.document.ticket_form.name.value == "") {
alert ("You must enter your name");
window.document.ticket_form.name.focus();
return;
}
if (window.document.ticket_form.cc_num.value == 0 ||
window.document.ticket_form.cc_num.value == ""){
alert ("You must enter a credit card number");
window.document.ticket_form.cc_num.focus();
return;
}
if (window.document.ticket_form.phone.value == 0 ||
window.document.ticket_form.phone.value == ""){
alert ("You must enter a phone number");
window.document.ticket_form.phone.focus();
return;
}

return;
}

my HTML form line is:

<form name="ticket_form" onSubmit="return validateForm();"
action="/cgi-bin/form2file?ticket-template" method=post>
 
D

dougawells

I tried return; return (true); return ("true"); return (0); all with
the same result - the CGI never gets called.
 
E

Evertjan.

I tried return; return (true); return ("true"); return (0); all with
the same result - the CGI never gets called.

How should we know what you are talking about?

Please quote what you are replying to.

If you want to post a followup via groups.google.com, don't use the
"Reply" link at the bottom of the article. Click on "show options" at the
top of the article, then click on the "Reply" at the bottom of the article
headers. <http://www.safalra.com/special/googlegroupsreply/>
 
L

Lee

(e-mail address removed) said:
This is my form validation subroutine:

function validateForm() {

if (window.document.ticket_form.name.value == 0 ||
window.document.ticket_form.name.value == "") {
alert ("You must enter your name");
window.document.ticket_form.name.focus();
return;
}
if (window.document.ticket_form.cc_num.value == 0 ||
window.document.ticket_form.cc_num.value == ""){
alert ("You must enter a credit card number");
window.document.ticket_form.cc_num.focus();
return;
}
if (window.document.ticket_form.phone.value == 0 ||
window.document.ticket_form.phone.value == ""){
alert ("You must enter a phone number");
window.document.ticket_form.phone.focus();
return;
}

return;
}

my HTML form line is:

<form name="ticket_form" onSubmit="return validateForm();"
action="/cgi-bin/form2file?ticket-template" method=post>

All of your returns except the last one should be:
return false;
The last one should be:
return true;


--
 

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,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top