Forum Moderators: open

Message Too Old, No Replies

Form Validation and Submission Acknowledgement

Form Validation Submission Acknowledgement Dreamweaver

         

Johnski

3:49 pm on Jun 2, 2005 (gmt 0)

10+ Year Member



Ive created a form in Dreamweaver that is sent via default Email client - No CGI scripting.
I have incorporated form validation using a standard yaromat Dreamweaver extension which works fine. When the form is correctly completed it is submitted via Outlook. Failure to cmplete it results in an error prompt.

The validation script is applied to the form using "on submit"

I want the user to be redirected to an acknowldedgement "form sent" page ONLY when the validation has been OKayed. I can only get it to do both, i.e it will still redirect to the acknowledgement page even if validation process hasnt been completed.

I have successfully managed to do this using CGI scripting on a form, but cant get it to work this way.

Thanks

RonPK

8:09 am on Jun 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Have the script return false when validation fails. Example:

if (valid) { 
// continue
} else {
alert("please enter your name");
return false;
}

Just a friendly reminder: keep in mind that on quite a number of PC's clicking on a mailto: link simply won't work. And that if it does launch the email client, not all the things you probably want to have in the subject and body fields will be transfered.

Johnski

10:08 am on Jun 3, 2005 (gmt 0)

10+ Year Member



Ron, Thanks for the response.

This particular form is for a Government Intranet system where everyone uses Outlook and the mailto: all works fine. No Scripting allowed im afraid which is why ive got to use this route. :)

Im not sure how to apply the java you advised me of, and would be grateful if you can advise how it would be applied to this very (one field) simple form. At the moment, regardless of the outcome of the validation the user is redirected to www.Yahoo.com. Where would the additional scripting need to be inserted to fix this so that if validation fails, the user is not proceeded to the webpage?

Many Thanks in Advance.

<html>
<head>
<title>Form Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
<!--
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function YY_checkform() { //v4.06
//copyright (c)1998,2001 Yaromat.com
var args = YY_checkform.arguments; var myDot=true; var myV=''; var myErr='';var addErr=false;var myReq;
for (var i=1; i<args.length;i=i+4){
if (args[i+1].charAt(0)=='#'){myReq=true; args[i+1]=args[i+1].substring(1);}else{myReq=false}
var myObj = MM_findObj(args[i].replace(/\[\d+\]/ig,""));
myV=myObj.value;
if (myObj.type=='text'¦¦myObj.type=='password'){
if (myReq&&myObj.value.length==0){addErr=true}
if ((myV.length>0)&&(args[i+2]==1)){ //fromto
if (!(myV/1)¦¦myV<args[i+1].split('_')[0]/1¦¦myV > args[i+1].split('_')[1]/1){addErr=true}
}
if ((myV.length>0)&&(args[i+2]==2)&&!myV.match("^[\\w\\.=-_]+@[\\w\\.-_]+\\.[a-z]{2,4}$")){addErr=true}// email
if ((myV.length>0)&&(args[i+2]==3)){ // date
var myMa=args[i+1].split("#"); var myAt=myV.match(myMa[0]);
if(myAt){
var myD=(myAt[myMa[1]])?myAt[myMa[1]]:1; var myM=myAt[myMa[2]]-1; var myY=myAt[myMa[3]];
var myDate=new Date(myY,myM,myD);
if(myDate.getFullYear()!=myY¦¦myDate.getDate()!=myD¦¦myDate.getMonth()!=myM){addErr=true};
}else{addErr=true}
}
if ((myV.length>0)&&(args[i+2]==4)){ // time
var myMa=args[i+1].split("#"); var myAt=myV.match(myMa[0]);if(!myAt){addErr=true}
}
if (myV.length>0&&args[i+2]==5){ // check this 2
var myObj1 = MM_findObj(args[i+1].replace(/\[\d+\]/ig,""));
if(myObj1.length)myObj1=myObj1[args[i+1].replace(/(.*\[)¦(\].*)/ig,"")];
if(!myObj1.checked){addErr=true}
}
if (myV.length>0&&args[i+2]==6){ // the same
var myObj1 = MM_findObj(args[i+1]);
if(myV!=myObj1.value){addErr=true}
}
}else
if (!myObj.type&&myObj.length>0&&myObj[0].type=='radio'){
var myTest = args[i].match(/(.*)\[(\d+)\].*/i);
var myObj1=(myObj.length>1)?myObj[myTest[2]]:myObj;
if (args[i+2]==1&&myObj1&&myObj1.checked&&MM_findObj(args[i+1]).value.length/1==0){addErr=true}
if (args[i+2]==2){
var myDot=false;
for(var j=0;j<myObj.length;j++){myDot=myDot¦¦myObj[j].checked}
if(!myDot){myErr+='* ' +args[i+3]+'\n'}
}
}else
if (myObj.type=='checkbox'){
if(args[i+2]==1&&myObj.checked==false){addErr=true}
if(args[i+2]==2&&myObj.checked&&MM_findObj(args[i+1]).value.length/1==0){addErr=true}
}else
if (myObj.type=='select-one'¦¦myObj.type=='select-multiple'){
if(args[i+2]==1&&myObj.selectedIndex/1==0){addErr=true}
}else
if (myObj.type=='textarea'){
if(myV.length<args[i+1]){addErr=true}
}
if (addErr){myErr+='* '+args[i+3]+'\n'; addErr=false}
}
if (myErr!=''){alert('The required information is incomplete or contains errors:\t\t\t\t\t\n\n'+myErr)}
document.MM_returnValue = (myErr=='');
}

function MM_goToURL() { //v3.0
var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
//-->
</script>
</head>

<body bgcolor="#FFFFFF" text="#000000">
<form name="form1" action="mailto:johnsmith@formtest.com?Subject=FORM TEST" method="post" enctype="text/plain" onSubmit="YY_checkform('form1','name','#q','0','You Must Enter Your Name');MM_goToURL('parent','http://www.yahoo.com');return document.MM_returnValue">
<p>Enter Your Name:
<input type="text" name="name">
</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>
</body>
</html>

RonPK

11:56 am on Jun 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here's a quick and dirty hack:

1. remove MM_goToURL('parent','http://www.yahoo.com'); from the onsubmit piece in the <form> tag

2. in the script, replace

if (myErr!=''){alert('The required information is incomplete or contains errors:\t\t\t\t\t\n\n'+myErr)}
document.MM_returnValue = (myErr=='');

with

if (myErr!=''){alert('The required information is incomplete or contains errors:\t\t\t\t\t\n\n'+myErr)} else {
MM_goToURL('parent','http://www.yahoo.com');
}
document.MM_returnValue = (myErr=='');

Johnski

2:50 pm on Jun 3, 2005 (gmt 0)

10+ Year Member



Ron,

Thanks for that - works a treat now... But one small problem in that after the form is successfully submitted, a IE prompt box is displayed that states:

This form is being submitted by email. Submitting this form will reveal your email address to the recipient...you may continue or cancel.

If you cancel, the user is still taken to the acknowledgement page when infact the email wont have been sent. Is there a known way around this?

Many Thanks