I have a form with a couple of text fields that get emailed to me when the user clicks Submit. What I am trying to do is show an alert message box saying Thank you your request has been submitted. Or Redirect to a Thank you page. I just can't seem to get Both the Submit button and the redirect to work together. Below is my code with out the redirect or alert..
<HTML>
<Tile><h1> Action Request Form </h1></Tilte>
<HEAD>
here is a message box that comes up.
you need to put this in your document right after you <body> tag
Code:
<SCRIPT LANGUAGE="JavaScript">
function checkdata()
{
var uppervalue;
if (document.WF_1.NAME.value.length == 0) {
alert ("The 'Name' field requires an entry.");
return false;
}
if (document.WF_1.Description.value.length == 0) {
alert ("The 'Description' field requires an entry.");
return false;
}
if (document.WF_1.time.value.length == 0) {
alert ("The 'Time' field requires an entry.");
return false;
}
return confirm('Thank You, Your application has been sent.');
}
// -- End of JavaScript code -------------- -->
</script>
then put this in your <form> tag-
Code:
onSubmit="return checkdata()"
if this doesn't work, you might need to put "name=WF_1" in your form tag.
It works I did have to put name="WF_1" in the Form Tag. also I had to give the name text a type of "text" <INPUT NAME="name" type="text" SIZE="30" >. I still get an Error on the Radio Buttons.
if (document.WF_1.time.value.length == 0) {
alert ("The 'Time' field requires an entry.");
return false;
}
The error is document WF_1.time.value.legnth is null or not an object. any ideas?
I got the same error on the WF_1 name but I noticed name was Capitalized Name after changing it that and the description fields work.
sorry my fault. I wasn't sure if that would work with radio buttons. so here is another one that checks for radio buttons. look closely as the form tag is in the javascript.
Can you use cgi? I think it would be easier to use that instead of javascript.
Code:
<script Language="Javascript">
<!-- Hide
function myWindow() {
if(!checkform()) return false;
var Name=document.WF_1.Name.value
var Description=document.WF_1.Description.value
var Time=document.WF_1.Time // it's an array...
for (var i=0;i < Time.length; i++){ // loop thru the array
if (Time[i].checked){ // if i. radio box is checked
Time = Time[i].value // passing its value to Time
break; // and jump out from the loop
}
}
formwindow=window.open("","formwindow","width=240,height=420,scrollbars=yes");
formwindow.document.write("<center><b>Is This Correct?</b></center>")
formwindow.document.write("<FORM NAME='myWindow'")
formwindow.document.write(" ACTION='mailto:[email protected]?subject=Action Request'")
formwindow.document.write(" ENCTYPE='TEXT/PLAIN'>")
// START OF PASSING DATAS TO THE WINDOW
// THE "PLACE" TO PASS
formwindow.document.write("<INPUT TYPE=hidden NAME=BODY>")
// MAKIN' AN "ALIAS"
msgData = formwindow.document.myWindow.BODY;
// PASSIN' THE DATA
msgData.value += "Name=" + escape(" ")+ Name + unescape("\n");
msgData.value += "Description=" + escape(" ")+ Description + unescape("\n");
msgData.value += "When=" + escape(" ")+ Time + unescape("\n");
// END OF PASSING DATAS TO THE WINDOW
formwindow.document.write("<center><b>Name=</b> ", Name,"<br>"+"<b>Description=</b> ",Description,"<br>"+"<b>When=</b> ", Time,"<br><br></center>");
formwindow.document.write("<center>If this is not the correct information")
formwindow.document.write(" then just close this window and fix what you have to.<br></center>");
formwindow.document.write("<center><INPUT TYPE='Submit' VALUE='Submit'></center>")
formwindow.document.write("</form>")
formwindow.document.close();
return false
}
function checkform() {
valid=true;
if(document.WF_1.Name.value=="") {
valid=false ;
alert("Please fill in the Name: textbox!");
}
if(document.WF_1.Description.value=="") {
valid=false ;
alert("Please fill in the Description: textbox!");
}
return valid;
}
//-->
</script>
then in your form part put this in place of your other form tag
<FORM NAME="WF_1" METHOD="POST" ENCTYPE="TEXT/PLAIN">
and then in your submit put this
I can use CGI I just don't know enough about it. If you have a CGI script for something like this maybe you can post it and I will give it a go! I tried the code from your last reply. It doesn't look at the radio buttons? nor will the mailto work? I have been trying to debug it but I'm not very good at HTML and Scripts. I am mainly a VB user.
WF_1 was just a name tha twas on one of my scripts. it really isn't anything.
Troy I am uploading the script, it is in text format. just rename the txt part to cgi.
now do you now where you perl path is or can you find out. I left it as the most common line so it should work. now when you upload it you have to do it in acsii mode and then chmod it to 755.
I will try them first thing in the morning when I get to work! Oh Buy the way I am using IIS for a web server not UNIX is that a problem? I noticed this is UNIX #!c:/perl/bin/perl Sorry I should have told you that to begin with. I'm a newbie to this Web development stuff.
It may be because of this line $mail_prog = '/usr/lib/sendmail' ; This points the the UNIX sendmail program. I am using Outlook and Exchange(which is not on the server). Hmm not sure where to go from here. I am downloading a Perl interpeter and I will try agian. I'll let you now
I am not sure if you need the shebang line for php on IIS, I have heard that you don't need it, but I needed at my ISP server. if it shows up in the page after you submit it then chances are you won't need it.
I tried that and all I can get it to do is bring up form.php. I'm assuming I needed to change form.txt to form.php? do I still need perl? or some other intereter running to read the form.php file?
ya I forgot to tell ya to rename it to form.php. I am not sure if IIS needs a php interpreter but you don't need perl. is it your server or your isp's?
It's My server so if need be I can install the php stuff. I just down loaded it from PHP. One thing that may be a problem is we use Exchange for a mail service instead of SMTP.
not postivie but you can change it to send through exchange. it is in the php.ini file. it will have something in there like
sendmail = localhost or /usr/lib/sendmail . i think you should be able to change that to your settings.