PDA

View Full Version : Help getting a contact form to work


JGoddard
11-25-2010, 12:06 PM
Can some one help in helping me to get an amended webpage I am working on to get a contact form to work.

The orginal worked with a mailto code, I wish to change this to use a php code instead. But when I first tested it with just a web page with contact fields it worked. I then amened the web page another person had created,and when I try to submit the form an error message comes up saying "error you must submit the form". Why is this message coming up, as I am using the same php code, which I used with the previous contact webpage and that worked fine previously but not now.

I've pasted a copy of the webpage below:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>PHP form to email sample form</title>
<!-- define some style elements-->
<style>
label,a
{
font-family : Arial, Helvetica, sans-serif;
font-size : 12px;
}
</style>
</head>

<body>
<head>
<title>Contact Us</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta content="Serif WebPlus X4" name="Generator">
<script src="wpscripts/jsNavBarFuncs.js" type="text/javascript"></script>
<script src="wpscripts/wp_navbar_menu.js" type="text/javascript"></script>
<link type="text/css" rel="stylesheet" href="wpscripts/wp_navbar_menu1.css">
<script src="customnavtree5.js" type="text/javascript"></script>
<script type="text/javascript">
</script>
<style type="text/css"><!--
body {margin: 0px; padding: 0px;}
a:link {color: #2c3651;}
a:visited {color: #1f5b8b;}
a:hover {color: #2c3651;}
a:active {color: #2c3651;}
.Artistic-Body-P
{
margin:0.0px 0.0px 0.0px 0.0px; text-align:left; font-weight:400;
}
.Normal-P
{
margin:0.0px 0.0px 0.0px 0.0px; text-align:center; font-weight:400;
}
.Artistic-Body-C
{
font-family:"Verdana", sans-serif; font-size:40.0px;
line-height:1.20em; color:#1f5b8b;
}
.Normal-C
{
font-family:"Arial", sans-serif; font-size:16.0px; line-height:1.19em;
}
.Body-Text---Col-C
{
font-family:"Verdana", sans-serif; font-size:16.0px;
line-height:1.13em;
}
.Body-Text---Col-C0
{
font-family:"Verdana", sans-serif; font-weight:700; font-size:16.0px;
line-height:1.13em;
}
--></style>
<script src="wpscripts/jspngfix.js" type="text/javascript"></script>
<script type="text/javascript"><!--
var blankSrc = "wpscripts/blank.gif";
--></script>
<script src="wpscripts/jsValidation.js" type="text/javascript"></script>
</head>
<div style="margin-left: auto; width: 1036px; margin-right: auto; position: relative; height: 1300px; background-color: transparent; text-align: left">
<div style="left: 0px; width: 1036px; position: absolute; top: 0px; height: 1300px"><img id="pic_1" title="" height="1300" alt="" width="1036" border="0" name="pic_1" src="wpimages/wp2ed15335_05.jpg"></div>
<div style="left: 0px; width: 1036px; position: absolute; top: 93px; height: 112px"><img id="pcrv_121" title="" height="112" alt="" width="1036" border="0" name="pcrv_121" src="wpimages/wp1248f703.png" onload="OnLoadPngFix()"></div>
<div style="left: 0px; width: 1035px; position: absolute; top: 1253px; height: 47px"><img id="meta_2" title="" height="47" alt="" width="1035" border="0" name="meta_2" src="wpimages/wpfae58d5a.png" onload="OnLoadPngFix()"></div>
<div style="left: 1002px; width: 33px; position: absolute; top: 0px; height: 1300px"><img id="meta_16" title="" height="1300" alt="" width="33" border="0" name="meta_16" src="wpimages/wpf3921bed.png" onload="OnLoadPngFix()"></div>
<div style="left: 0px; width: 1036px; position: absolute; top: 0px; height: 47px"><img id="meta_15" title="" height="47" alt="" width="1036" border="0" name="meta_15" src="wpimages/wpb44fdd7a.png" onload="OnLoadPngFix()"></div>
<div style="left: 212px; width: 422px; position: absolute; top: 68px; height: 50px"><img id="art_6" title="" height="50" alt=" Dimensions Swindon" width="422" border="0" name="art_6" src="wpimages/wp76f3d426.png" onload="OnLoadPngFix()"></div>
<div style="left: 141px; width: 102px; position: absolute; top: 69px; height: 48px">
<div class="Artistic-Body-P"><span class="Artistic-Body-C">new</span></div></div>
<div style="left: 0px; width: 31px; position: absolute; top: 0px; height: 1300px"><img id="meta_19" title="" height="1300" alt="" width="31" border="0" name="meta_19" src="wpimages/wpad2990c9.png" onload="OnLoadPngFix()"></div>
<div id="txt_16" style="left: 234px; overflow: hidden; width: 545px; position: absolute; top: 1251px; height: 49px; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box">
<p class="Normal-P"><span class="Normal-C">New Dimensions | Registered Charity No: 1011107 | Company No: 2709623 </span></p>
<p class="Normal-P"><span class="Normal-C">All rights reserved. Copyright © 2009. New Dimensions.</span></p></div>
<div style="left: 10px; width: 165px; position: absolute; top: 8px; height: 223px"><img id="meta_20" title="" height="223" alt="" width="165" border="0" name="meta_20" src="wpimages/wp188f3ead.png" onload="OnLoadPngFix()"></div>
<script id="nav_365_script" type="text/javascript"><!--
try {
var navtree_nav_365 = WpNavBar.getNavTreeCustom( customNavTree5, {m_sThisPageUrl:'page4.html',
m_sNavBarTarget:'_self',
m_bFlash:false,
m_bIncludeChildren:true,
m_bIsCustom:true} );
if( !navtree_nav_365 ) throw WpNavBar.getErrorObj( 'Link tree could not be read' );
var nav_365 = new wp_navbar_menu("nav_365", navtree_nav_365, {'m_optAlignment':1,'m_optGap':2,'m_optFirstPopupP osition':0,'m_opTimeOut':500,'m_optShowBelow':1,'m _optShowRight':1,m_sId:'nav_365',
m_sScriptId:'nav_365_script',
m_iLeft:65,
m_iTop:348,
m_sCssClass:'wp_navbar_menu1',
m_iWidth:130,
m_iHeight:405}, null);
} catch(e){
document.write( '<div style="position:absolute;left:65;top:348;width:130;height :405">There was an error generating the navbar:<br>' + e.message + '</div>' );
}
--></script>
<div style="left: 455px; width: 234px; position: absolute; top: 288px; height: 43px"><img id="grp_1" title="" height="43" alt="" width="234" border="0" name="grp_1" src="wpimages/wpc757cf33.png" onload="OnLoadPngFix()"></div>
<div style="left: 233px; width: 8px; position: absolute; top: 389px; height: 14px"><img id="pcrv_159" title="" height="14" alt="" width="8" border="0" name="pcrv_159" src="wpimages/wp5e4dd591.png" onload="OnLoadPngFix()"></div>
<div style="left: 243px; width: 9px; position: absolute; top: 392px; height: 11px"><img id="pcrv_160" title="" height="11" alt="" width="9" border="0" name="pcrv_160" src="wpimages/wpc32fb473.png" onload="OnLoadPngFix()"></div>
<div style="left: 254px; width: 6px; position: absolute; top: 392px; height: 10px"><img id="pcrv_161" title="" height="10" alt="" width="6" border="0" name="pcrv_161" src="wpimages/wp5c595961.png" onload="OnLoadPngFix()"></div>
<div style="left: 266px; width: 8px; position: absolute; top: 392px; height: 11px"><img id="pcrv_162" title="" height="11" alt="" width="8" border="0" name="pcrv_162" src="wpimages/wp81954bbd.png" onload="OnLoadPngFix()"></div>
<div style="left: 277px; width: 9px; position: absolute; top: 392px; height: 11px"><img id="pcrv_163" title="" height="11" alt="" width="9" border="0" name="pcrv_163" src="wpimages/wpb732be48.png" onload="OnLoadPngFix()"></div>
<div style="left: 292px; width: 3px; position: absolute; top: 388px; height: 14px"><img id="pcrv_164" title="" height="14" alt="" width="3" border="0" name="pcrv_164" src="wpimages/wp294e8a82.png" onload="OnLoadPngFix()"></div>
<div style="left: 296px; width: 9px; position: absolute; top: 392px; height: 11px"><img id="pcrv_165" title="" height="11" alt="" width="9" border="0" name="pcrv_165" src="wpimages/wpac61fb49.png" onload="OnLoadPngFix()"></div>
<div style="left: 306px; width: 6px; position: absolute; top: 388px; height: 14px"><img id="pcrv_166" title="" height="14" alt="" width="6" border="0" name="pcrv_166" src="wpimages/wp60d8fc84.png" onload="OnLoadPngFix()"></div>
<div style="left: 312px; width: 9px; position: absolute; top: 392px; height: 11px"><img id="pcrv_167" title="" height="11" alt="" width="9" border="0" name="pcrv_167" src="wpimages/wp677d836d.png" onload="OnLoadPngFix()"></div>
<div style="left: 323px; width: 6px; position: absolute; top: 392px; height: 10px"><img id="pcrv_168" title="" height="10" alt="" width="6" border="0" name="pcrv_168" src="wpimages/wp5c595961.png" onload="OnLoadPngFix()"></div>
<div style="left: 330px; width: 14px; position: absolute; top: 392px; height: 11px"><img id="pcrv_169" title="" height="11" alt="" width="14" border="0" name="pcrv_169" src="wpimages/wpf931ad92.png" onload="OnLoadPngFix()"></div>
<div style="left: 346px; width: 8px; position: absolute; top: 392px; height: 11px"><img id="pcrv_170" title="" height="11" alt="" width="8" border="0" name="pcrv_170" src="wpimages/wp99e90360.png" onload="OnLoadPngFix()"></div>
<div style="left: 357px; width: 3px; position: absolute; top: 388px; height: 14px"><img id="pcrv_171" title="" height="14" alt="" width="3" border="0" name="pcrv_171" src="wpimages/wpa387641f.png" onload="OnLoadPngFix()"></div>
<div style="left: 366px; width: 8px; position: absolute; top: 392px; height: 11px"><img id="pcrv_172" title="" height="11" alt="" width="8" border="0" name="pcrv_172" src="wpimages/wp5e490f00.png" onload="OnLoadPngFix()"></div>
<div style="left: 375px; width: 9px; position: absolute; top: 388px; height: 14px"><img id="pcrv_173" title="" height="14" alt="" width="9" border="0" name="pcrv_173" src="wpimages/wp9a2594ab.png" onload="OnLoadPngFix()"></div>
<div style="left: 384px; width: 8px; position: absolute; top: 392px; height: 11px"><img id="pcrv_174" title="" height="11" alt="" width="8" border="0" name="pcrv_174" src="wpimages/wp81954bbd.png" onload="OnLoadPngFix()"></div>
<div style="left: 394px; width: 6px; position: absolute; top: 389px; height: 14px"><img id="pcrv_175" title="" height="14" alt="" width="6" border="0" name="pcrv_175" src="wpimages/wp0053ffd7.png" onload="OnLoadPngFix()"></div>
<div style="left: 407px; width: 9px; position: absolute; top: 392px; height: 11px"><img id="pcrv_176" title="" height="11" alt="" width="9" border="0" name="pcrv_176" src="wpimages/wp9d9a79ae.png" onload="OnLoadPngFix()"></div>
<div style="left: 418px; width: 6px; position: absolute; top: 392px; height: 10px"><img id="pcrv_177" title="" height="10" alt="" width="6" border="0" name="pcrv_177" src="wpimages/wp5c595961.png" onload="OnLoadPngFix()"></div>
<div style="left: 429px; width: 10px; position: absolute; top: 392px; height: 10px"><img id="pcrv_178" title="" height="10" alt="" width="10" border="0" name="pcrv_178" src="wpimages/wpf4d2e84e.png" onload="OnLoadPngFix()"></div>
<div style="left: 441px; width: 3px; position: absolute; top: 388px; height: 14px"><img id="pcrv_179" title="" height="14" alt="" width="3" border="0" name="pcrv_179" src="wpimages/wp294e8a82.png" onload="OnLoadPngFix()"></div>
<div style="left: 444px; width: 8px; position: absolute; top: 392px; height: 11px"><img id="pcrv_180" title="" height="11" alt="" width="8" border="0" name="pcrv_180" src="wpimages/wp8983b907.png" onload="OnLoadPngFix()"></div>
<div style="left: 454px; width: 3px; position: absolute; top: 388px; height: 14px"><img id="pcrv_181" title="" height="14" alt="" width="3" border="0" name="pcrv_181" src="wpimages/wp294e8a82.png" onload="OnLoadPngFix()"></div>
<div style="left: 457px; width: 6px; position: absolute; top: 389px; height: 14px"><img id="pcrv_182" title="" height="14" alt="" width="6" border="0" name="pcrv_182" src="wpimages/wp0053ffd7.png" onload="OnLoadPngFix()"></div>
<div style="left: 471px; width: 9px; position: absolute; top: 392px; height: 14px"><img id="pcrv_183" title="" height="14" alt="" width="9" border="0" name="pcrv_183" src="wpimages/wpe33f98a1.png" onload="OnLoadPngFix()"></div>
<div style="left: 481px; width: 3px; position: absolute; top: 388px; height: 14px"><img id="pcrv_184" title="" height="14" alt="" width="3" border="0" name="pcrv_184" src="wpimages/wpa387641f.png" onload="OnLoadPngFix()"></div>
<div style="left: 484px; width: 9px; position: absolute; top: 392px; height: 11px"><img id="pcrv_185" title="" height="11" alt="" width="9" border="0" name="pcrv_185" src="wpimages/wp40645cb2.png" onload="OnLoadPngFix()"></div>
<div style="left: 495px; width: 8px; position: absolute; top: 392px; height: 11px"><img id="pcrv_186" title="" height="11" alt="" width="8" border="0" name="pcrv_186" src="wpimages/wp99e90360.png" onload="OnLoadPngFix()"></div>
<div style="left: 505px; width: 8px; position: absolute; top: 392px; height: 11px"><img id="pcrv_187" title="" height="11" alt="" width="8" border="0" name="pcrv_187" src="wpimages/wp69142869.png" onload="OnLoadPngFix()"></div>
<div style="left: 514px; width: 9px; position: absolute; top: 392px; height: 11px"><img id="pcrv_188" title="" height="11" alt="" width="9" border="0" name="pcrv_188" src="wpimages/wpd1cb5032.png" onload="OnLoadPngFix()"></div>
<div style="left: 530px; width: 9px; position: absolute; top: 392px; height: 14px"><img id="pcrv_189" title="" height="14" alt="" width="9" border="0" name="pcrv_189" src="wpimages/wp5cdc0642.png" onload="OnLoadPngFix()"></div>
<div style="left: 541px; width: 9px; position: absolute; top: 388px; height: 14px"><img id="pcrv_190" title="" height="14" alt="" width="9" border="0" name="pcrv_190" src="wpimages/wp9a2594ab.png" onload="OnLoadPngFix()"></div>
<div style="left: 550px; width: 9px; position: absolute; top: 392px; height: 11px"><img id="pcrv_191" title="" height="11" alt="" width="9" border="0" name="pcrv_191" src="wpimages/wp677d836d.png" onload="OnLoadPngFix()"></div>
<div style="left: 561px; width: 9px; position: absolute; top: 392px; height: 11px"><img id="pcrv_192" title="" height="11" alt="" width="9" border="0" name="pcrv_192" src="wpimages/wpac61fb49.png" onload="OnLoadPngFix()"></div>
<div style="left: 571px; width: 9px; position: absolute; top: 392px; height: 11px"><img id="pcrv_193" title="" height="11" alt="" width="9" border="0" name="pcrv_193" src="wpimages/wp7d047502.png" onload="OnLoadPngFix()"></div>
<div style="left: 233px; width: 8px; position: absolute; top: 411px; height: 14px"><img id="pcrv_194" title="" height="14" alt="" width="8" border="0" name="pcrv_194" src="wpimages/wp390effde.png" onload="OnLoadPngFix()"></div>
<div style="left: 243px; width: 3px; position: absolute; top: 411px; height: 14px"><img id="pcrv_195" title="" height="14" alt="" width="3" border="0" name="pcrv_195" src="wpimages/wp294e8a82.png" onload="OnLoadPngFix()"></div>
<div style="left: 248px; width: 9px; position: absolute; top: 414px; height: 11px"><img id="pcrv_196" title="" height="11" alt="" width="9" border="0" name="pcrv_196" src="wpimages/wpfdcae3e9.png" onload="OnLoadPngFix()"></div>
<div style="left: 263px; width: 9px; position: absolute; top: 414px; height: 11px"><img id="pcrv_197" title="" height="11" alt="" width="9" border="0" name="pcrv_197" src="wpimages/wpc32fb473.png" onload="OnLoadPngFix()"></div>
<div style="left: 273px; width: 6px; position: absolute; top: 415px; height: 10px"><img id="pcrv_198" title="" height="10" alt="" width="6" border="0" name="pcrv_198" src="wpimages/wp5c595961.png" onload="OnLoadPngFix()"></div>
<div style="left: 285px; width: 7px; position: absolute; top: 411px; height: 14px"><img id="pcrv_199" title="" height="14" alt="" width="7" border="0" name="pcrv_199" src="wpimages/wp1baef809.png" onload="OnLoadPngFix()"></div>
<div style="left: 293px; width: 8px; position: absolute; top: 414px; height: 11px"><img id="pcrv_200" title="" height="11" alt="" width="8" border="0" name="pcrv_200" src="wpimages/wpbf2a44c0.png" onload="OnLoadPngFix()"></div>
<div style="left: 304px; width: 9px; position: absolute; top: 414px; height: 11px"><img id="pcrv_201" title="" height="11" alt="" width="9" border="0" name="pcrv_201" src="wpimages/wpb732be48.png" onload="OnLoadPngFix()"></div>
<div style="left: 315px; width: 3px; position: absolute; top: 415px; height: 10px"><img id="pcrv_202" title="" height="10" alt="" width="3" border="0" name="pcrv_202" src="wpimages/wp61fe2bdd.png" onload="OnLoadPngFix()"></div>
<div style="left: 228px; width: 24px; position: absolute; top: 469px; height: 58px"><img id="grp_5" title="" height="58" alt="" width="24" border="0" name="grp_5" src="wpimages/wp690286b7.png" onload="OnLoadPngFix()"></div>
<div style="left: 226px; width: 26px; position: absolute; top: 529px; height: 70px"><img id="grp_11" title="" height="70" alt="" width="26" border="0" name="grp_11" src="wpimages/wp6b3e9162.png" onload="OnLoadPngFix()"></div>
<div id="txt_25" style="left: 273px; overflow: hidden; width: 254px; position: absolute; top: 472px; height: 20px; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box">
<p class="Artistic-Body-P"><span class="Body-Text---Col-C">Tel (01793) 485786</span></p></div>
<div id="txt_14" style="left: 273px; overflow: hidden; width: 290px; position: absolute; top: 527px; height: 92px; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box">
<p class="Artistic-Body-P"><span class="Body-Text---Col-C0">New Dimensions</span></p>
<p class="Artistic-Body-P"><span class="Body-Text---Col-C">Former&nbsp;Even Swindon School Building<br>
Romsey Street<br>
Swindon<br>
SN2 2ER</span></div>
<div id="txt_15" style="left: 275px; overflow: hidden; width: 302px; position: absolute; top: 635px; height: 21px; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box">
<p class="Artistic-Body-P"><span class="Body-Text---Col-C">E-mail <a href="http://www.serifwebresources.com/maps/GoogleMapObject.html?w=953&amp;h=460&amp;lat=51.5677073228 203330&amp;lng=-1.8018436431884766&amp;z=16&amp;t=1&amp;nc=FULL&amp;mc=BAR&amp;sw=1&amp;mq =1&amp;mn1=New%20Dimensions&amp;mlt1=51.5673471991430930&amp;m lg1=-1.8016290664672852&amp;mt1=Former%20Even%20Swindon%20S chool%20%20%20%20Romsey%20Street%20%20%20%20Swindo n%20%20%20%20SN2%202ER%20%20%20%20%20%20%20%20%20% 20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20 %20"></iframe></div></div>
<p>&nbsp;</p>
</body>
</html>

gentleone
11-25-2010, 02:14 PM
Where is the PHP code from your form?
It's also a good idea to clean up your code first. You've used twice the head tag and there is no opening body tag.

davidj
11-26-2010, 06:43 AM
Looks like you copied and pasted code from another page hence the 2 head tags

JGoddard
11-26-2010, 12:15 PM
Here is copy of the php code I am using with the above page:
Why can't I copy the full code, as part of it keeps disappearing?

JGoddard
11-26-2010, 12:31 PM
I don't mean to keep duplicating my message, but I have trouble copying and pasting the code. As a section keeping being removed, when I save my reply.

JGoddard
11-26-2010, 12:32 PM
Here is copy of the php code I am using with the above page:
<?php
if(!isset($_POST['submit']))
{
//This page should not be accessed directly. Need to submit the form.
echo "error; you need to submit the form!";
}
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];
//Validate first
if(empty($name)||empty($visitor_email))
{
echo "Name and email are mandatory!";
exit;
}
if(IsInjected($visitor_email))
{
echo "Bad email value!";
exit;
}
$email_from = "jg@yahoo.com";//<== update the email address
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
//Send the email!
mail($to,$email_subject,$email_body,$headers);
//done. redirect to thank-you page.
header('Location: thank-you.html');

// Function to validate against any email injection attempts
function IsInjected($str)
{
$injections = array('(\n+)',
'(\r+)',
'(\t+)',
'(%0A+)',
'(%0D+)',
'(%08+)',
'(%09+)'
);
$inject = join('|', $injections);
$inject = "/$inject/i";
if(preg_match($inject,$str))
{
return true;
}
else
{
return false;
}
}

?>

gentleone
11-26-2010, 01:28 PM
Why can't I copy the full code, as part of it keeps disappearing?
You'll have to wrapped your code in code, html or php tags in the advanced editor. To go to the advanced editor click on the 'POST REPLY' button on the left underneath the thread or click underneath the 'quick reply' box on the 'Go Advanced' button.

edbr
11-27-2010, 01:01 AM
you need to define $to

$to="mymail@my_domain.com"; to specify where the mail will be sent

JGoddard
11-27-2010, 12:47 PM
Thanks but this is the part that kept disappearing when I was trying to paste in the code in the last posted reply.

This is the part that was missing:
$to = "name@yahoo.com";//<== update the email address
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
//Send the email!
mail($to,$email_subject,$email_body,$headers);
//done. redirect to thank-you page.
header('Location: thank-you.html');
(this part comes after the email from paragraph)

Any idea why the script linked into the web page does not work?

edbr
11-29-2010, 05:27 AM
the error you mention sis not included in the php is it therefor the javascript validation you have added also?
try with out it to see if it then is sent

edbr
11-29-2010, 05:28 AM
do you have a live link?

JGoddard
11-29-2010, 03:03 PM
No I haven't set the page as live as yet, as I am trying to rectify the problem first, but I can test the page up on the webhost.

The validation script is separate as well, here is a copy of the code below:-
/*
-------------------------------------------------------------------------
JavaScript Form Validator (gen_validatorv31.js)
Version 3.1.2
Copyright (C) 2003-2008 JavaScript-Coder.com. All rights reserved.
You can freely use this script in your Web pages.
You may adapt this script for your own needs, provided these opening credit
lines are kept intact.

The Form validation script is distributed free from JavaScript-Coder.com
For updates, please visit:
http://www.javascript-coder.com/html-form/javascript-form-validation.phtml

Questions & comments please send to form.val at javascript-coder.com
-------------------------------------------------------------------------
*/
function Validator(frmname)
{
this.formobj=document.forms[frmname];
if(!this.formobj)
{
alert("Error: couldnot get Form object "+frmname);
return;
}
if(this.formobj.onsubmit)
{
this.formobj.old_onsubmit = this.formobj.onsubmit;
this.formobj.onsubmit=null;
}
else
{
this.formobj.old_onsubmit = null;
}
this.formobj._sfm_form_name=frmname;
this.formobj.onsubmit=form_submit_handler;
this.addValidation = add_validation;
this.setAddnlValidationFunction=set_addnl_vfunctio n;
this.clearAllValidations = clear_all_validations;
this.disable_validations = false;//new
document.error_disp_handler = new sfm_ErrorDisplayHandler();
this.EnableOnPageErrorDisplay=validator_enable_OPE D;
this.EnableOnPageErrorDisplaySingleBox=validator_e nable_OPED_SB;
this.show_errors_together=true;
this.EnableMsgsTogether=sfm_enable_show_msgs_toget her;
document.set_focus_onerror=true;
this.EnableFocusOnError=sfm_validator_enable_focus ;
}
function sfm_validator_enable_focus(enable)
{
document.set_focus_onerror = enable;
}
function set_addnl_vfunction(functionname)
{
this.formobj.addnlvalidation = functionname;
}
function sfm_set_focus(objInput)
{
if(document.set_focus_onerror)
{
objInput.focus();
}
}
function sfm_enable_show_msgs_together()
{
this.show_errors_together=true;
this.formobj.show_errors_together=true;
}
function clear_all_validations()
{
for(var itr=0;itr < this.formobj.elements.length;itr++)
{
this.formobj.elements[itr].validationset = null;
}
}
function form_submit_handler()
{
var bRet = true;
document.error_disp_handler.clear_msgs();
for(var itr=0;itr < this.elements.length;itr++)
{
if(this.elements[itr].validationset &&
!this.elements[itr].validationset.validate())
{
bRet = false;
}
if(!bRet && !this.show_errors_together)
{
break;
}
}
if(this.addnlvalidation)
{
str =" var ret = "+this.addnlvalidation+"()";
eval(str);
if(!ret)
{
bRet=false;
}
}
if(!bRet)
{
document.error_disp_handler.FinalShowMsg();
return false;
}
return true;
}
function add_validation(itemname,descriptor,errstr)
{
var condition = null;
if(arguments.length > 3)
{
condition = arguments[3];
}
if(!this.formobj)
{
alert("Error: The form object is not set properly");
return;
}//if
var itemobj = this.formobj[itemname];
if(itemobj.length && isNaN(itemobj.selectedIndex) )
//for radio button; don't do for 'select' item
{
itemobj = itemobj[0];
}
if(!itemobj)
{
alert("Error: Couldnot get the input object named: "+itemname);
return;
}
if(!itemobj.validationset)
{
itemobj.validationset = new ValidationSet(itemobj,this.show_errors_together);
}
itemobj.validationset.add(descriptor,errstr,condit ion);
itemobj.validatorobj=this;
}
function validator_enable_OPED()
{
document.error_disp_handler.EnableOnPageDisplay(fa lse);
}
function validator_enable_OPED_SB()
{
document.error_disp_handler.EnableOnPageDisplay(tr ue);
}
function sfm_ErrorDisplayHandler()
{
this.msgdisplay = new AlertMsgDisplayer();
this.EnableOnPageDisplay= edh_EnableOnPageDisplay;
this.ShowMsg=edh_ShowMsg;
this.FinalShowMsg=edh_FinalShowMsg;
this.all_msgs=new Array();
this.clear_msgs=edh_clear_msgs;
}
function edh_clear_msgs()
{
this.msgdisplay.clearmsg(this.all_msgs);
this.all_msgs = new Array();
}
function edh_FinalShowMsg()
{
this.msgdisplay.showmsg(this.all_msgs);
}
function edh_EnableOnPageDisplay(single_box)
{
if(true == single_box)
{
this.msgdisplay = new SingleBoxErrorDisplay();
}
else
{
this.msgdisplay = new DivMsgDisplayer();
}
}
function edh_ShowMsg(msg,input_element)
{

var objmsg = new Array();
objmsg["input_element"] = input_element;
objmsg["msg"] = msg;
this.all_msgs.push(objmsg);
}
function AlertMsgDisplayer()
{
this.showmsg = alert_showmsg;
this.clearmsg=alert_clearmsg;
}
function alert_clearmsg(msgs)
{
}
function alert_showmsg(msgs)
{
var whole_msg="";
var first_elmnt=null;
for(var m=0;m < msgs.length;m++)
{
if(null == first_elmnt)
{
first_elmnt = msgs[m]["input_element"];
}
whole_msg += msgs[m]["msg"] + "\n";
}

alert(whole_msg);
if(null != first_elmnt)
{
sfm_set_focus(first_elmnt);
}
}
function sfm_show_error_msg(msg,input_elmt)
{
document.error_disp_handler.ShowMsg(msg,input_elmt );
}
function SingleBoxErrorDisplay()
{
this.showmsg=sb_div_showmsg;
this.clearmsg=sb_div_clearmsg;
}
function sb_div_clearmsg(msgs)
{
var divname = form_error_div_name(msgs);
show_div_msg(divname,"");
}
function sb_div_showmsg(msgs)
{
var whole_msg="<ul>\n";
for(var m=0;m < msgs.length;m++)
{
whole_msg += "<li>" + msgs[m]["msg"] + "</li>\n";
}
whole_msg += "</ul>";
var divname = form_error_div_name(msgs);
show_div_msg(divname,whole_msg);
}
function form_error_div_name(msgs)
{
var input_element= null;
for(var m in msgs)
{
input_element = msgs[m]["input_element"];
if(input_element){break;}
}
var divname ="";
if(input_element)
{
divname = input_element.form._sfm_form_name + "_errorloc";
}
return divname;
}
function DivMsgDisplayer()
{
this.showmsg=div_showmsg;
this.clearmsg=div_clearmsg;
}
function div_clearmsg(msgs)
{
for(var m in msgs)
{
var divname = element_div_name(msgs[m]["input_element"]);
show_div_msg(divname,"");
}
}
function element_div_name(input_element)
{
var divname = input_element.form._sfm_form_name + "_" +
input_element.name + "_errorloc";
divname = divname.replace(/[\[\]]/gi,"");
return divname;
}
function div_showmsg(msgs)
{
var whole_msg;
var first_elmnt=null;
for(var m in msgs)
{
if(null == first_elmnt)
{
first_elmnt = msgs[m]["input_element"];
}
var divname = element_div_name(msgs[m]["input_element"]);
show_div_msg(divname,msgs[m]["msg"]);
}
if(null != first_elmnt)
{
sfm_set_focus(first_elmnt);
}
}
function show_div_msg(divname,msgstring)
{
if(divname.length<=0) return false;
if(document.layers)
{
divlayer = document.layers[divname];
if(!divlayer){return;}
divlayer.document.open();
divlayer.document.write(msgstring);
divlayer.document.close();
}
else
if(document.all)
{
divlayer = document.all[divname];
if(!divlayer){return;}
divlayer.innerHTML=msgstring;
}
else
if(document.getElementById)
{
divlayer = document.getElementById(divname);
if(!divlayer){return;}
divlayer.innerHTML =msgstring;
}
divlayer.style.visibility="visible";
}
function ValidationDesc(inputitem,desc,error,condition)
{
this.desc=desc;
this.error=error;
this.itemobj = inputitem;
this.condition = condition;
this.validate=vdesc_validate;
}
function vdesc_validate()
{
if(this.condition != null )
{
if(!eval(this.condition))
{
return true;
}
}
if(!validateInput(this.desc,this.itemobj,this.erro r))
{
this.itemobj.validatorobj.disable_validations=true ;
sfm_set_focus(this.itemobj);
return false;
}
return true;
}
function ValidationSet(inputitem,msgs_together)
{
this.vSet=new Array();
this.add= add_validationdesc;
this.validate= vset_validate;
this.itemobj = inputitem;
this.msgs_together = msgs_together;
}
function add_validationdesc(desc,error,condition)
{
this.vSet[this.vSet.length]=
new ValidationDesc(this.itemobj,desc,error,condition);
}
function vset_validate()
{
var bRet = true;
for(var itr=0;itr<this.vSet.length;itr++)
{
bRet = bRet && this.vSet[itr].validate();
if(!bRet && !this.msgs_together)
{
break;
}
}
return bRet;
}
function validateEmail(email)
{
var splitted = email.match("^(.+)@(.+)$");
if(splitted == null) return false;
if(splitted[1] != null )
{
var regexp_user=/^\"?[\w-_\.]*\"?$/;
if(splitted[1].match(regexp_user) == null) return false;
}
if(splitted[2] != null)
{
var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
if(splitted[2].match(regexp_domain) == null)
{
var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
if(splitted[2].match(regexp_ip) == null) return false;
}// if
return true;
}
return false;
}
function IsCheckSelected(objValue,chkValue)
{
var selected=false;
var objcheck = objValue.form.elements[objValue.name];
if(objcheck.length)
{
var idxchk=-1;
for(var c=0;c < objcheck.length;c++)
{
if(objcheck[c].value == chkValue)
{
idxchk=c;
break;
}//if
}//for
if(idxchk>= 0)
{
if(objcheck[idxchk].checked=="1")
{
selected=true;
}
}//if
}
else
{
if(objValue.checked == "1")
{
selected=true;
}//if
}//else
return selected;
}
function TestDontSelectChk(objValue,chkValue,strError)
{
var pass = true;
pass = IsCheckSelected(objValue,chkValue)?false:true;
if(pass==false)
{
if(!strError || strError.length ==0)
{
strError = "Can't Proceed as you selected "+objValue.name;
}//if
sfm_show_error_msg(strError,objValue);

}
return pass;
}
function TestShouldSelectChk(objValue,chkValue,strError)
{
var pass = true;
pass = IsCheckSelected(objValue,chkValue)?true:false;
if(pass==false)
{
if(!strError || strError.length ==0)
{
strError = "You should select "+objValue.name;
}//if
sfm_show_error_msg(strError,objValue);

}
return pass;
}
function TestRequiredInput(objValue,strError)
{
var ret = true;
var val = objValue.value;
val = val.replace(/^\s+|\s+$/g,"");//trim
if(eval(val.length) == 0)
{
if(!strError || strError.length ==0)
{
strError = objValue.name + " : Required Field";
}//if
sfm_show_error_msg(strError,objValue);
ret=false;
}//if
return ret;
}
function TestMaxLen(objValue,strMaxLen,strError)
{
var ret = true;
if(eval(objValue.value.length) > eval(strMaxLen))
{
if(!strError || strError.length ==0)
{
strError = objValue.name + " : "+ strMaxLen +" characters maximum ";
}//if
sfm_show_error_msg(strError,objValue);
ret = false;
}//if
return ret;
}
function TestMinLen(objValue,strMinLen,strError)
{
var ret = true;
if(eval(objValue.value.length) < eval(strMinLen))
{
if(!strError || strError.length ==0)
{
strError = objValue.name + " : " + strMinLen + " characters minimum ";
}//if
sfm_show_error_msg(strError,objValue);
ret = false;
}//if
return ret;
}
function TestInputType(objValue,strRegExp,strError,strDefau ltError)
{
var ret = true;
var charpos = objValue.value.search(strRegExp);
if(objValue.value.length > 0 && charpos >= 0)
{
if(!strError || strError.length ==0)
{
strError = strDefaultError;
}//if
sfm_show_error_msg(strError,objValue);
ret = false;
}//if
return ret;
}
function TestEmail(objValue,strError)
{
var ret = true;
if(objValue.value.length > 0 && !validateEmail(objValue.value) )
{
if(!strError || strError.length ==0)
{
strError = objValue.name+": Enter a valid Email address ";
}//if
sfm_show_error_msg(strError,objValue);
ret = false;
}//if
return ret;
}
function TestLessThan(objValue,strLessThan,strError)
{
var ret = true;
if(isNaN(objValue.value))
{
sfm_show_error_msg(objValue.name +": Should be a number ",objValue);
ret = false;
}//if
else
if(eval(objValue.value) >= eval(strLessThan))
{
if(!strError || strError.length ==0)
{
strError = objValue.name + " : value should be less than "+ strLessThan;
}//if
sfm_show_error_msg(strError,objValue);
ret = false;
}//if
return ret;
}
function TestGreaterThan(objValue,strGreaterThan,strError)
{
var ret = true;
if(isNaN(objValue.value))
{
sfm_show_error_msg(objValue.name+": Should be a number ",objValue);
ret = false;
}//if
else
if(eval(objValue.value) <= eval(strGreaterThan))
{
if(!strError || strError.length ==0)
{
strError = objValue.name + " : value should be greater than "+ strGreaterThan;
}//if
sfm_show_error_msg(strError,objValue);
ret = false;
}//if
return ret;
}
function TestRegExp(objValue,strRegExp,strError)
{
var ret = true;
if( objValue.value.length > 0 &&
!objValue.value.match(strRegExp) )
{
if(!strError || strError.length ==0)
{
strError = objValue.name+": Invalid characters found ";
}//if
sfm_show_error_msg(strError,objValue);
ret = false;
}//if
return ret;
}
function TestDontSelect(objValue,dont_sel_index,strError)
{
var ret = true;
if(objValue.selectedIndex == null)
{
sfm_show_error_msg("ERROR: dontselect command for non-select Item");
ret = false;
}
if(objValue.selectedIndex == eval(dont_sel_index))
{
if(!strError || strError.length ==0)
{
strError = objValue.name+": Please Select one option ";
}//if
sfm_show_error_msg(strError,objValue);
ret = false;
}
return ret;
}
function TestSelectOneRadio(objValue,strError)
{
var objradio = objValue.form.elements[objValue.name];
var one_selected=false;
for(var r=0;r < objradio.length;r++)
{
if(objradio[r].checked)
{
one_selected=true;
break;
}
}
if(false == one_selected)
{
if(!strError || strError.length ==0)
{
strError = "Please select one option from "+objValue.name;
}
sfm_show_error_msg(strError,objValue);
}
return one_selected;
}
function validateInput(strValidateStr,objValue,strError)
{
var ret = true;
var epos = strValidateStr.search("=");
var command = "";
var cmdvalue = "";
if(epos >= 0)
{
command = strValidateStr.substring(0,epos);
cmdvalue = strValidateStr.substr(epos+1);
}
else
{
command = strValidateStr;
}
switch(command)
{
case "req":
case "required":
{
ret = TestRequiredInput(objValue,strError)
break;
}//case required
case "maxlength":
case "maxlen":
{
ret = TestMaxLen(objValue,cmdvalue,strError)
break;
}//case maxlen
case "minlength":
case "minlen":
{
ret = TestMinLen(objValue,cmdvalue,strError)
break;
}//case minlen
case "alnum":
case "alphanumeric":
{
ret = TestInputType(objValue,"[^A-Za-z0-9]",strError,
objValue.name+": Only alpha-numeric characters allowed ");
break;
}
case "alnum_s":
case "alphanumeric_space":
{
ret = TestInputType(objValue,"[^A-Za-z0-9\\s]",strError,
objValue.name+": Only alpha-numeric characters and space allowed ");
break;
}
case "num":
case "numeric":
{
ret = TestInputType(objValue,"[^0-9]",strError,
objValue.name+": Only digits allowed ");
break;
}
case "dec":
case "decimal":
{
ret = TestInputType(objValue,"[^0-9\.]",strError,
objValue.name+": Only numbers allowed ");
break;
}
case "alphabetic":
case "alpha":
{
ret = TestInputType(objValue,"[^A-Za-z]",strError,
objValue.name+": Only alphabetic characters allowed ");
break;
}
case "alphabetic_space":
case "alpha_s":
{
ret = TestInputType(objValue,"[^A-Za-z\\s]",strError,
objValue.name+": Only alphabetic characters and space allowed ");
break;
}
case "email":
{
ret = TestEmail(objValue,strError);
break;
}
case "lt":
case "lessthan":
{
ret = TestLessThan(objValue,cmdvalue,strError);
break;
}
case "gt":
case "greaterthan":
{
ret = TestGreaterThan(objValue,cmdvalue,strError);
break;
}//case greaterthan
case "regexp":
{
ret = TestRegExp(objValue,cmdvalue,strError);
break;
}
case "dontselect":
{
ret = TestDontSelect(objValue,cmdvalue,strError)
break;
}
case "dontselectchk":
{
ret = TestDontSelectChk(objValue,cmdvalue,strError)
break;
}
case "shouldselchk":
{
ret = TestShouldSelectChk(objValue,cmdvalue,strError)
break;
}
case "selone_radio":
{
ret = TestSelectOneRadio(objValue,strError);
break;
}
}//switch
return ret;
}
function VWZ_IsListItemSelected(listname,value)
{
for(var i=0;i < listname.options.length;i++)
{
if(listname.options[i].selected == true &&
listname.options[i].value == value)
{
return true;
}
}
return false;
}
function VWZ_IsChecked(objcheck,value)
{
if(objcheck.length)
{
for(var c=0;c < objcheck.length;c++)
{
if(objcheck[c].checked == "1" &&
objcheck[c].value == value)
{
return true;
}
}
}
else
{
if(objcheck.checked == "1" )
{
return true;
}
}
return false;
}
/*
Copyright (C) 2003-2009 JavaScript-Coder.com . All rights reserved.
*/

edbr
11-30-2010, 01:20 AM
you need a mail server to send mail of course, as for the error, where do you see it ? in an alert box or on the 'action' page

davidj
11-30-2010, 11:29 AM
@JGoddard (http://www.dreamweaverclub.com/forum/member.php?u=30433)

Please wrap your code in code tags when posting

JGoddard
11-30-2010, 12:24 PM
you need a mail server to send mail of course, as for the error, where do you see it ? in an alert box or on the 'action' page

the error message comes up on a new webpage.
This is the message:
error; you need to submit the form!Name and email are mandatory!

edbr
12-01-2010, 02:00 AM
right so its a php error

if(empty($name)||empty($visitor_email))
{
echo "Name and email are mandatory!";
exit;
}
the form elements are not being passed, it is looking for
$name = $_POST['name'];
$visitor_email = $_POST['email'];
make sure ,that your form had the correctly named fields
ie name and email.
and that the form is method POST of course

JGoddard
12-09-2010, 03:40 PM
thanks for all your help and advice. I've finally found the problem, not only was it the names that were conflicting with the php script, but it only worked after I changed the id label to name instead. So simple, but annoying.:-D