Jump to content

Recommended Posts

Hi,

 

I just edit this coding from

 

echo "<form id='form1' name='form1' method='post' action=''>

 

to

echo "<form id='form1' name='form1' method='post' action='contact_sucess.php'>

 

after i tested , the validation are not working.

the actual coding is 

<?
function fcCreateForm($localTitle="Mr.",$localName="",$localCompanyName="",$localPosition="",$localCompanyAddress="",$localEmail="",$localPhone="",$localBusinessNature="",$localCompanyHomepage="http://",$localComment="")//this function create enquiry form
{

$localName=fcStringReplace($localName);
$localCompanyName=fcStringReplace($localCompanyName);
$localPosition=fcStringReplace($localPosition);
$localCompanyAddress=fcStringReplace($localCompanyAddress);
$localEmail=fcStringReplace($localEmail);
$localPhone=fcStringReplace($localPhone);
$localBusinessNature=fcStringReplace($localBusinessNature);
$localCompanyHomepage=fcStringReplace($localCompanyHomepage);
$localComment=fcStringReplace($localComment);

$arrayTitle=array("Mr.","Mrs.","Miss.","Mdm.");
$i=0;

echo "<form id='form1' name='form1' method='post' action='contact_sucess.php'>
<input type='hidden' name='hidFirstRun' value='no'/>
    <table width='400' border='0' cellspacing='0' cellpadding='6'>
      <tr>
        <td colspan='2' align='left' valign='top'><table width='400' border='0' cellspacing='0' style='padding-left:6px; padding-right:6px;'>
          <tr>
            <td width='100' align='right' valign='middle'>Title : </td>
            <td width='50'><select name='slTitle'>";

             while ($i < sizeof($arrayTitle))
{
echo "<option value='".$arrayTitle[$i]."'";
if ($arrayTitle[$i]==$localTitle)
{
echo "' selected='selected'>".$arrayTitle[$i]."";
}else{
echo "'>".$arrayTitle[$i]."";
}
echo "</option>";
$i++;
}
		  
            echo "</select>
            </td>
            <td width='50' align='right' valign='middle'>Name : </td>
            <td width='200' align='left' valign='middle'><input type='text' name='txtName' value='".$localName."'/>
              <font color='#FF0000'>*</font></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td width='150' align='right' valign='middle'>Company Name : </td>
        <td width='250' align='left' valign='middle'><input type='text' name='txtCompanyName' style='width:60%;' value='".$localCompanyName."'/></td>
      </tr>
      <tr>
        <td width='150' align='right' valign='middle'>Position In Company : </td>
        <td width='250' align='left' valign='middle'><input type='text' name='txtPosition' value='".$localPosition."'/></td>
      </tr>
      <tr>
        <td width='150' align='right' valign='top'>Company Address : </td>
        <td width='250' align='left' valign='top'><textarea name='taCompanyAddress' rows='4' style='width:80%;'>".$localCompanyAddress."</textarea></td>
      </tr>
      <tr>
        <td align='right' valign='middle'>Email : </td>
        <td width='250' align='left' valign='middle'><input type='text' name='txtEmail' style='width:60%;' value='".$localEmail."'/>
          <font color='#FF0000'>*</font></td>
      </tr>
      <tr>
        <td width='150' align='right' valign='middle'>Phone : </td>
        <td width='250' align='left' valign='middle'><input type='text' name='txtPhone' style='width:60%;' value='".$localPhone."'/>
          <font color='#FF0000'>*</font></td>
      </tr>
      <tr>
        <td width='150' align='right' valign='middle'>Business Nature of Company : </td>
        <td width='250' align='left' valign='middle'><input type='text' name='txtBusinessNature' style='width:80%;' value='".$localBusinessNature."'/></td>
      </tr>
      <tr>
        <td align='right' valign='middle'>Company Homepage if any : </td>
        <td align='left' valign='middle'><input type='text' name='txtCompanyHomepage' style='width:80%;' value='".$localCompanyHomepage."'/></td>
      </tr>
      <tr>
        <td align='right' valign='top'>Your Requests or Comments : </td>
        <td align='left' valign='top'><textarea name='taComment' rows='10' style='width:100%;'>".$localComment."</textarea></td>
      </tr>
      <tr>
        <td align='right' valign='middle'> </td>
        <td align='left' valign='middle'><input type='submit' name='Submit' value='Send Enquiry' /></td>
      </tr>
    </table>
  </form>";
}//end of function

//function that validate inputed data
function fcValidateData($localName,$localEmail,$localPhone)
{
if(empty($localName) || empty($localEmail) || empty($localPhone))
{
if (empty($localName)){echo "<font color='red'>Please enter your name.</font><br/>";}
if (empty($localEmail)){echo "<font color='red'>Please enter your email.</font><br/>";}
if (empty($localPhone)){echo "<font color='red'>Please enter your phone number.</font><br/>";}
return false;
}else{
$validateEmail=fcEmailCheck($localEmail);
if ($validateEmail)//inputed email is in valid format
{
return true;
}else{//email address is invalid
echo "<font color='red'>Please enter a valid email address.</font>";
return false;
}
}
}//end of function

function fcEmailCheck($str) //email validation
{ 
$str = strtolower($str);
if(ereg("^([^[:space:]]+)@(.+)\.(ad|ae|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|cr|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|fi|fj|fk|fm|fo|fr|fx|ga|gb|gov|gd|ge|gf|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nato|nc|ne|net|nf|ng|ni|nl|no|np|nr|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$",$str)){
return true;//validate pass
} else {
return false;//validate fail
}

}//end of function

function fcStringReplace($localCheckMessage)
{
  $localCheckMessage=str_replace("\'","&#39;",$localCheckMessage);
  $localCheckMessage=str_replace("\\\\","\\",$localCheckMessage);
$localCheckMessage=str_replace("\\\"","&#34;",$localCheckMessage);
return $localCheckMessage;
  }//end of function
  
  function fcStringReplaceText($localCheckMessage)
{
  $localCheckMessage=str_replace("\'","'",$localCheckMessage);
  $localCheckMessage=str_replace("\\\\","\\",$localCheckMessage);
$localCheckMessage=str_replace("\\\"","\"",$localCheckMessage);
$localCheckMessage=str_replace("&#39;","'",$localCheckMessage);
$localCheckMessage=str_replace("&#34;","\"",$localCheckMessage);
return $localCheckMessage;
  }//end of function
  
  function fcSendMail()
{
//error_reporting(0);//turn off error report

require("rotator_config.php");
mysql_connect($databaseHost,$databaseUser,$databasePassword);//connect to mysql server
mysql_select_db($databaseName);//select database

$query="select count(*) as totalData from target";//query
$result=mysql_query($query);//retrieve data

while ($row=mysql_fetch_array($result))
{
$totalData=$row['totalData'];//get email total
}

$query="select count from rotate_count";
$result=mysql_query($query);

while ($row=mysql_fetch_array($result))
{
$offset=$row['count']-1;
$query="select target from target limit $offset,1";//query that retrieve email address
$result=mysql_query($query);

while ($row=mysql_fetch_array($result))
{
$recipient=$row['target'];
}
}

$localName=$_POST["slTitle"]." ".fcStringReplaceText($_POST["txtName"]);
$localCompanyName=fcStringReplaceText($_POST["txtCompanyName"]);
$localPosition=fcStringReplaceText($_POST["txtPosition"]);
$localCompanyAddress=fcStringReplaceText($_POST["taCompanyAddress"]);
$localEmail=$_POST["txtEmail"];
$localPhone=fcStringReplaceText($_POST["txtPhone"]);
$localBusinessNature=fcStringReplaceText($_POST["txtBusinessNature"]);
$localCompanyHomepage=fcStringReplaceText($_POST["txtCompanyHomepage"]);
$localComment=fcStringReplaceText($_POST["taComment"]);

//$recipient = "sean@netbizsolutions.com";//Mail send to
$subject = "NetBiz Solutions Enquiry";//Mail Subject
$mailheader = "From: $localEmail\n";
$mailheader .= "Reply-To: $localEmail\n";
$message  = "Name: $localName\n\n";
$message .= "Company Name: $localCompanyName\n\n";
$message .= "Position: $localPosition\n\n";
$message .= "Company Address: $localCompanyAddress\n\n";
$message .= "Email: $localEmail\n\n";
$message .= "Phone Number: $localPhone\n\n";
$message .= "Business Nature: $localBusinessNature\n\n";
$message .= "Company Homepage: $localCompanyHomepage\n\n";
$message .= "Message: $localComment";
$boolMailSent=@mail($recipient, $subject, $message, $mailheader);//sending mail

if ($boolMailSent==false) {
echo "<font color='red'>Sorry! Fail to deliver enquiry, please try again.</font>";
}else{
$offset=$offset+2;
if ($offset>$totalData){$offset=1;}
$query="update rotate_count set count=$offset";
$result=mysql_query($query);
echo "Your enquiry has been sent, please allow up to 2 working days for us to get back to you. Thank you for your patience.";
}
}  

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/template_basic.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Internet Advertising Consultancy NetBizSolutions Internet Advertising Guru</title>
<META NAME="Keywords" CONTENT="Internet Advertising Consultancy, Internet Advertising Guru, Internet Advertising Consultants, Malaysia Web Design,Malaysia Web Hosting">
<META NAME="Description" CONTENT="NetBizSolutions, Your Internet Advertising Consultancy is led by Internet advertising Guru, Eugene Yeng. We specialize in Malaysia Web Design, Malaysia Web Hosting, Content Management systems and Internet Advertising.">
<META NAME="Copyright" CONTENT="Copyright © 2001 NetBizSolutions.com . All rights reserved">
<META NAME="Distribution" CONTENT="Global">
<META NAME="Rating" CONTENT="General">
<META NAME="Robots" CONTENT="All">
<META NAME="Revisit-After" CONTENT="7 Days">
<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
<script src="images/AC_RunActiveContent.js" type="text/javascript"></script>
<script src="images/AC_ActiveX.js" type="text/javascript"></script>
<link href="default.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div align="center">
  <table width="780" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td align="center" valign="top"><script type="text/javascript">
AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0','width','780','height','200','src','images/top','quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','images/top' ); //end AC code
</script><noscript><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="780" height="200">
        <param name="movie" value="images/top.swf" />
        <param name="quality" value="high" />
        <embed src="images/top.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="780" height="200"></embed>
      </object></noscript></td>
    </tr>
    <tr>
      <td align="left" valign="top"><script type="text/javascript">
AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0','width','780','height','30','src','images/nav','quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','images/nav' ); //end AC code
</script><noscript><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="780" height="30">
        <param name="movie" value="images/nav.swf" />
        <param name="quality" value="high" />
        <embed src="images/nav.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="780" height="30"></embed>
      </object></noscript></td>
    </tr>
    <tr>
      <td align="left" valign="top"><table width="780" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="230" align="left" valign="top" style="background-image:url(internet-advertising-consultancy-graphics/internet-advertising-guru-side-r.jpg); background-position:left; background-repeat:repeat-y;"><table width="230" border="0" cellspacing="0" cellpadding="0" >
              <tr>
                <td align="left" valign="top"><img src="internet-advertising-consultancy-graphics/internet-advertising-guru-logo.jpg" alt="internet advertising consultancy, NetBizSolutions company logo" width="230" height="140" title="internet advertising consultancy, NetBizSolutions company logo"/></td>
              </tr>
              <tr>
                <td><table width="230" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td align="left" valign="top"><img src="internet-advertising-consultancy-graphics/internet-advertising-guru-sideh1.jpg" width="230" height="25" /></td>
                    </tr>
                    <tr>
                      <td align="left" valign="top" style="background-image:url(internet-advertising-consultancy-graphics/internet-advertising-guru-sideh1-r.jpg); background-position:left; background-repeat:repeat-y;"><table width="230" border="0" cellspacing="0" cellpadding="0">
                        



		<tr>
                          <td width="20"> </td>
                          
		<td width="200"><div class="sideWhite">
                            <h1 align="left">What our clients say</h1>

			test
		</div></td>
                          
		<td width="10"> </td>
                        
		</tr>






                      </table></td>
                    </tr>
                    <tr>
                      <td align="left" valign="top"><img src="internet-advertising-consultancy-graphics/internet-advertising-guru-sideh2.jpg" width="230" height="20" /></td>
                    </tr>
                    <tr>
                      <td align="left" valign="top" style="background-image:url(internet-advertising-consultancy-graphics/internet-advertising-guru-sideh2-r.jpg); background-position:left; background-repeat:repeat-y;"><table width="230" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                          <td width="20"> </td>
                          <td width="200"><div align="center"><img src="internet-advertising-consultancy-graphics/internet-advertising-guru-top-rank-yahoo-msn.jpg" alt="We are Ranked Top "Internet Advertising Consultancy"! " title="We are Ranked Top "Internet Advertising Consultancy"! "/></div>
                          <div class="sideBlack">
                            <h1>We are Ranked Top "Internet Advertising Consultancy"!                            </h1>
                            <p>Google, Yahoo Asia and MSN have ranked Netbizsolutions.com as the top Internet Advertising Consultancy out of millions of other consultancies. We also have high standings for Internet Advertising Guru and Internet Advertising Consultant. We thank our competitors for making us better.</p>                          </div></td>
                          <td width="10"> </td>
                        </tr>
                      </table></td>
                    </tr>
                    <tr>
                      <td align="left" valign="top"><img src="internet-advertising-consultancy-graphics/internet-advertising-guru-foot.jpg" width="230" height="20" /></td>
                    </tr>
                </table></td>
              </tr>
          </table></td>
          <td width="550" align="left" valign="top"><table width="550" cellpadding="10">
            <tr><td><!-- InstanceBeginEditable name="EditRegion1" -->
		<h1>Contact Us</h1>
		<div align="center">
		<?
  if(!isset($_POST["hidFirstRun"])){
  fcCreateForm();//call function to create form
  }else{
  
  $validateResult=fcValidateData($_POST["txtName"],$_POST["txtEmail"],$_POST["txtPhone"]);
  
  if ($validateResult)//inputed data are valid
  {
  fcSendMail();//send mail
  }else{//inputed data are invalid or empty
  fcCreateForm($_POST["slTitle"],$_POST["txtName"],$_POST["txtCompanyName"],$_POST["txtPosition"],$_POST["taCompanyAddress"],$_POST["txtEmail"],$_POST["txtPhone"],$_POST["txtBusinessNature"],$_POST["txtCompanyHomepage"],$_POST["taComment"]);//call function to create form
  }
  
  }
  ?></div>

<br>
NetBizSolutions Services<br>
12-1, Jalan 5/109f,<br>
Plaza Danau 2, Taman Danau Desa,<br>
58100, Kuala Lumpur.<br>
<br>
Tel : 03-79808237<br>
<br>
<br>
View our Street map<br />
<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps/ms?hl=en&ie=UTF8&oe=UTF8&msa=0&msid=104091506452304834273.00046729040437617dfef&ll=3.099336,101.687179&spn=0.029997,0.036478&z=14&output=embed"></iframe><br /><br /><medium>View <a href="http://maps.google.com/maps/ms?hl=en&ie=UTF8&oe=UTF8&msa=0&msid=104091506452304834273.00046729040437617dfef&ll=3.099336,101.687179&spn=0.029997,0.036478&z=14&source=embed" style="color:#0000FF;text-align:left" target="_blank">NetBizSolutions.com</a> in a larger map</medium>     

<br>

<!-- Google Code for pageview Conversion Page -->
<script language="JavaScript" type="text/javascript">
<!--
var google_conversion_id = 1071839760;
var google_conversion_language = "en_US";
var google_conversion_format = "1";
var google_conversion_color = "000000";
if (1) {
  var google_conversion_value = 1;
}
var google_conversion_label = "pageview";
//-->
</script>
<script language="JavaScript" src="http://www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<img height=1 width=1 border=0 src="http://www.googleadservices.com/pagead/conversion/1071839760/imp.gif?value=1&label=pageview&script=0">
</noscript>
<br>
                                  







<!-- InstanceEndEditable --></td>
            </tr></table></td>
        </tr>
      </table></td>
    </tr>

    <tr>
      <td align="left" valign="top"><table width="780" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="220"> </td>
          <td width="20" align="left" valign="top"><img src="internet-advertising-consultancy-graphics/internet-advertising-guru-bottom1.jpg" width="20" height="15" /></td>
          <td width="530" style=" background-image:url(internet-advertising-consultancy-graphics/internet-advertising-guru-bottom1-r.jpg); background-position:top; background-repeat:repeat-x;"></td>
          <td width="10" align="right" valign="top"><img src="internet-advertising-consultancy-graphics/internet-advertising-guru-bottom2.jpg" width="10" height="15" /></td>
        </tr>




        	<tr>
	<td> 

	</td>
</tr>
        <tr>
          <td colspan="3" align="right"><div class="bottomLink">
            <a href="index.htm">Home</a>
            <a href="http://www.netbizasia.com/advertising.htm">Services</a>
            <a href="portfolio.html">Portfolio</a>
            <a href="news.html">News</a>
            <a href="location.htm">Location</a>
            <a href="contact.php">Contact Us</a>		 
      
            <a href="killer_internet_cashflow_strategies.html">Our Books</a> 
            <a href="workshops.html">Workshops</a> 
            <a href="malaysia-web-design.htm">Web Design</a> 
    <br>
   </td>
          <td width="10" align="right" valign="top"> </td>
        </tr>
        <tr>
          <td> </td>
          <td align="left" valign="top"> </td>
          <td align="right" valign="top"><div class="copyright">Copyright © 2001 Netbizsolutions Services</div></td>
          <td align="right" valign="top"> </td>
        </tr>
<tr>
	<td> 

	</td>
</tr>





      </table></td>
    </tr>
  </table>
  <div class="copyright"></div>
</div>
</body>
<!-- InstanceEnd --></html>

Link to comment
https://forums.phpfreaks.com/topic/167452-solved-validation/
Share on other sites

Your validation is being done in the same file that contains the form.

 

If you change the form tag to

echo "<form id='form1' name='form1' method='post' action='contact_sucess.php'>

 

Your are changing its action target so it won't be able to validate the data for you.

 

Change that back to :

echo "<form id='form1' name='form1' method='post' action=''>

 

then as mmarif4u mentioned too, edit your code like this:

 

if ($result=mysql_query($query))
{
header ("location: contact_sucess.php");
exit;
}

 

you gotta remove the

echo "Your enquiry has been sent, please allow up to 2 working days for us to get back to you. Thank you for your patience.";

 

since it makes no sense you wanna redirect him to another page.

 

Link to comment
https://forums.phpfreaks.com/topic/167452-solved-validation/#findComment-883070
Share on other sites

Your validation is being done in the same file that contains the form.

 

If you change the form tag to

echo "<form id='form1' name='form1' method='post' action='contact_sucess.php'>

 

Your are changing its action target so it won't be able to validate the data for you.

 

Change that back to :

echo "<form id='form1' name='form1' method='post' action=''>

 

then as mmarif4u mentioned too, edit your code like this:

 

if ($result=mysql_query($query))
{
header ("location: contact_sucess.php");
exit;
}

 

you gotta remove the

echo "Your enquiry has been sent, please allow up to 2 working days for us to get back to you. Thank you for your patience.";

 

since it makes no sense you wanna redirect him to another page.

 

 

 

can i know where to add the line

 

if ($result=mysql_query($query))
{
header ("location: contact_sucess.php");
exit;
}

 

in my script?

Sorry i am new in PHP

Link to comment
https://forums.phpfreaks.com/topic/167452-solved-validation/#findComment-883163
Share on other sites

it is correct if i put it in this line ?

 

 
if ($boolMailSent==false) {
echo "<font color='red'>Sorry! Fail to deliver enquiry, please try again.</font>";
}else{
$offset=$offset+2;
if ($offset>$totalData){$offset=1;}
$query="update rotate_count set count=$offset";
$result=mysql_query($query);
{
$redirect = 'contact_success.php';
header ("location: $redirect");
}
}
}  

but it doesn't redirect .why ?

Link to comment
https://forums.phpfreaks.com/topic/167452-solved-validation/#findComment-883165
Share on other sites

this is my edited code

 

<?
function fcCreateForm($localTitle="Mr.",$localName="",$localCompanyName="",$localPosition="",$localCompanyAddress="",$localEmail="",$localPhone="",$localBusinessNature="",$localCompanyHomepage="http://",$localComment="")//this function create enquiry form
{

$localName=fcStringReplace($localName);
$localCompanyName=fcStringReplace($localCompanyName);
$localPosition=fcStringReplace($localPosition);
$localCompanyAddress=fcStringReplace($localCompanyAddress);
$localEmail=fcStringReplace($localEmail);
$localPhone=fcStringReplace($localPhone);
$localBusinessNature=fcStringReplace($localBusinessNature);
$localCompanyHomepage=fcStringReplace($localCompanyHomepage);
$localComment=fcStringReplace($localComment);

$arrayTitle=array("Mr.","Mrs.","Miss.","Mdm.");
$i=0;

echo "<form id='form1' name='form1' method='post' action=''>
<input type='hidden' name='hidFirstRun' value='no'/>
    <table width='400' border='0' cellspacing='0' cellpadding='6'>
      <tr>
        <td colspan='2' align='left' valign='top'><table width='400' border='0' cellspacing='0' style='padding-left:6px; padding-right:6px;'>
          <tr>
            <td width='100' align='right' valign='middle'>Title : </td>
            <td width='50'><select name='slTitle'>";

             while ($i < sizeof($arrayTitle))
{
echo "<option value='".$arrayTitle[$i]."'";
if ($arrayTitle[$i]==$localTitle)
{
echo "' selected='selected'>".$arrayTitle[$i]."";
}else{
echo "'>".$arrayTitle[$i]."";
}
echo "</option>";
$i++;
}
		  
            echo "</select>
            </td>
            <td width='50' align='right' valign='middle'>Name : </td>
            <td width='200' align='left' valign='middle'><input type='text' name='txtName' value='".$localName."'/>
              <font color='#FF0000'>*</font></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td width='150' align='right' valign='middle'>Company Name : </td>
        <td width='250' align='left' valign='middle'><input type='text' name='txtCompanyName' style='width:60%;' value='".$localCompanyName."'/></td>
      </tr>
      <tr>
        <td width='150' align='right' valign='middle'>Position In Company : </td>
        <td width='250' align='left' valign='middle'><input type='text' name='txtPosition' value='".$localPosition."'/></td>
      </tr>
      <tr>
        <td width='150' align='right' valign='top'>Company Address : </td>
        <td width='250' align='left' valign='top'><textarea name='taCompanyAddress' rows='4' style='width:80%;'>".$localCompanyAddress."</textarea></td>
      </tr>
      <tr>
        <td align='right' valign='middle'>Email : </td>
        <td width='250' align='left' valign='middle'><input type='text' name='txtEmail' style='width:60%;' value='".$localEmail."'/>
          <font color='#FF0000'>*</font></td>
      </tr>
      <tr>
        <td width='150' align='right' valign='middle'>Phone : </td>
        <td width='250' align='left' valign='middle'><input type='text' name='txtPhone' style='width:60%;' value='".$localPhone."'/>
          <font color='#FF0000'>*</font></td>
      </tr>
      <tr>
        <td width='150' align='right' valign='middle'>Business Nature of Company : </td>
        <td width='250' align='left' valign='middle'><input type='text' name='txtBusinessNature' style='width:80%;' value='".$localBusinessNature."'/></td>
      </tr>
      <tr>
        <td align='right' valign='middle'>Company Homepage if any : </td>
        <td align='left' valign='middle'><input type='text' name='txtCompanyHomepage' style='width:80%;' value='".$localCompanyHomepage."'/></td>
      </tr>
      <tr>
        <td align='right' valign='top'>Your Requests or Comments : </td>
        <td align='left' valign='top'><textarea name='taComment' rows='10' style='width:100%;'>".$localComment."</textarea></td>
      </tr>
      <tr>
        <td align='right' valign='middle'> </td>
        <td align='left' valign='middle'><input type='submit' name='Submit' value='Send Enquiry' /></td>
      </tr>
    </table>
  </form>";
}//end of function

//function that validate inputed data
function fcValidateData($localName,$localEmail,$localPhone)
{
if(empty($localName) || empty($localEmail) || empty($localPhone))
{
if (empty($localName)){echo "<font color='red'>Please enter your name.</font><br/>";}
if (empty($localEmail)){echo "<font color='red'>Please enter your email.</font><br/>";}
if (empty($localPhone)){echo "<font color='red'>Please enter your phone number.</font><br/>";}
return false;
}else{
$validateEmail=fcEmailCheck($localEmail);
if ($validateEmail)//inputed email is in valid format
{
return true;
}else{//email address is invalid
echo "<font color='red'>Please enter a valid email address.</font>";
return false;
}
}
}//end of function

function fcEmailCheck($str) //email validation
{ 
$str = strtolower($str);
if(ereg("^([^[:space:]]+)@(.+)\.(ad|ae|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|cr|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|fi|fj|fk|fm|fo|fr|fx|ga|gb|gov|gd|ge|gf|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nato|nc|ne|net|nf|ng|ni|nl|no|np|nr|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$",$str)){
return true;//validate pass
} else {
return false;//validate fail
}

}//end of function

function fcStringReplace($localCheckMessage)
{
  $localCheckMessage=str_replace("\'","'",$localCheckMessage);
  $localCheckMessage=str_replace("\\\\","\\",$localCheckMessage);
$localCheckMessage=str_replace("\\\"",""",$localCheckMessage);
return $localCheckMessage;
  }//end of function
  
  function fcStringReplaceText($localCheckMessage)
{
  $localCheckMessage=str_replace("\'","'",$localCheckMessage);
  $localCheckMessage=str_replace("\\\\","\\",$localCheckMessage);
$localCheckMessage=str_replace("\\\"","\"",$localCheckMessage);
$localCheckMessage=str_replace("'","'",$localCheckMessage);
$localCheckMessage=str_replace(""","\"",$localCheckMessage);
return $localCheckMessage;
  }//end of function
  
  function fcSendMail()
{
//error_reporting(0);//turn off error report

require("rotator_config.php");
mysql_connect($databaseHost,$databaseUser,$databasePassword);//connect to mysql server
mysql_select_db($databaseName);//select database

$query="select count(*) as totalData from target";//query
$result=mysql_query($query);//retrieve data

while ($row=mysql_fetch_array($result))
{
$totalData=$row['totalData'];//get email total
}

$query="select count from rotate_count";
$result=mysql_query($query);

while ($row=mysql_fetch_array($result))
{
$offset=$row['count']-1;
$query="select target from target limit $offset,1";//query that retrieve email address
$result=mysql_query($query);

while ($row=mysql_fetch_array($result))
{
$recipient=$row['target'];
}
}

$localName=$_POST["slTitle"]." ".fcStringReplaceText($_POST["txtName"]);
$localCompanyName=fcStringReplaceText($_POST["txtCompanyName"]);
$localPosition=fcStringReplaceText($_POST["txtPosition"]);
$localCompanyAddress=fcStringReplaceText($_POST["taCompanyAddress"]);
$localEmail=$_POST["txtEmail"];
$localPhone=fcStringReplaceText($_POST["txtPhone"]);
$localBusinessNature=fcStringReplaceText($_POST["txtBusinessNature"]);
$localCompanyHomepage=fcStringReplaceText($_POST["txtCompanyHomepage"]);
$localComment=fcStringReplaceText($_POST["taComment"]);

//$recipient = "sean@netbizsolutions.com";//Mail send to
$subject = "NetBiz Solutions Enquiry";//Mail Subject
$mailheader = "From: $localEmail\n";
$mailheader .= "Reply-To: $localEmail\n";
$message  = "Name: $localName\n\n";
$message .= "Company Name: $localCompanyName\n\n";
$message .= "Position: $localPosition\n\n";
$message .= "Company Address: $localCompanyAddress\n\n";
$message .= "Email: $localEmail\n\n";
$message .= "Phone Number: $localPhone\n\n";
$message .= "Business Nature: $localBusinessNature\n\n";
$message .= "Company Homepage: $localCompanyHomepage\n\n";
$message .= "Message: $localComment";
$boolMailSent=@mail($recipient, $subject, $message, $mailheader);//sending mail

if ($boolMailSent==false) {
echo "<font color='red'>Sorry! Fail to deliver enquiry, please try again.</font>";
}else{
$offset=$offset+2;
if ($offset>$totalData){$offset=1;}
$query="update rotate_count set count=$offset";
$result=mysql_query($query);
header ('location:contact_success.php');

}
}  

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/template_basic.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Internet Advertising Consultancy NetBizSolutions Internet Advertising Guru</title>
<META NAME="Keywords" CONTENT="Internet Advertising Consultancy, Internet Advertising Guru, Internet Advertising Consultants, Malaysia Web Design,Malaysia Web Hosting">
<META NAME="Description" CONTENT="NetBizSolutions, Your Internet Advertising Consultancy is led by Internet advertising Guru, Eugene Yeng. We specialize in Malaysia Web Design, Malaysia Web Hosting, Content Management systems and Internet Advertising.">
<META NAME="Copyright" CONTENT="Copyright © 2001 NetBizSolutions.com . All rights reserved">
<META NAME="Distribution" CONTENT="Global">
<META NAME="Rating" CONTENT="General">
<META NAME="Robots" CONTENT="All">
<META NAME="Revisit-After" CONTENT="7 Days">
<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
<script src="images/AC_RunActiveContent.js" type="text/javascript"></script>
<script src="images/AC_ActiveX.js" type="text/javascript"></script>
<link href="default.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div align="center">
  <table width="780" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td align="center" valign="top"><script type="text/javascript">
AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0','width','780','height','200','src','images/top','quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','images/top' ); //end AC code
</script><noscript><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="780" height="200">
        <param name="movie" value="images/top.swf" />
        <param name="quality" value="high" />
        <embed src="images/top.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="780" height="200"></embed>
      </object></noscript></td>
    </tr>
    <tr>
      <td align="left" valign="top"><script type="text/javascript">
AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0','width','780','height','30','src','images/nav','quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','images/nav' ); //end AC code
</script><noscript><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="780" height="30">
        <param name="movie" value="images/nav.swf" />
        <param name="quality" value="high" />
        <embed src="images/nav.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="780" height="30"></embed>
      </object></noscript></td>
    </tr>
    <tr>
      <td align="left" valign="top"><table width="780" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="230" align="left" valign="top" style="background-image:url(internet-advertising-consultancy-graphics/internet-advertising-guru-side-r.jpg); background-position:left; background-repeat:repeat-y;"><table width="230" border="0" cellspacing="0" cellpadding="0" >
              <tr>
                <td align="left" valign="top"><img src="internet-advertising-consultancy-graphics/internet-advertising-guru-logo.jpg" alt="internet advertising consultancy, NetBizSolutions company logo" width="230" height="140" title="internet advertising consultancy, NetBizSolutions company logo"/></td>
              </tr>
              <tr>
                <td><table width="230" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td align="left" valign="top"><img src="internet-advertising-consultancy-graphics/internet-advertising-guru-sideh1.jpg" width="230" height="25" /></td>
                    </tr>
                    <tr>
                      <td align="left" valign="top" style="background-image:url(internet-advertising-consultancy-graphics/internet-advertising-guru-sideh1-r.jpg); background-position:left; background-repeat:repeat-y;"><table width="230" border="0" cellspacing="0" cellpadding="0">
                        



		<tr>
                          <td width="20"> </td>
                          
		<td width="200"><div class="sideWhite">
                            <h1 align="left">What our clients say</h1>

			test
		</div></td>
                          
		<td width="10"> </td>
                        
		</tr>






                      </table></td>
                    </tr>
                    <tr>
                      <td align="left" valign="top"><img src="internet-advertising-consultancy-graphics/internet-advertising-guru-sideh2.jpg" width="230" height="20" /></td>
                    </tr>
                    <tr>
                      <td align="left" valign="top" style="background-image:url(internet-advertising-consultancy-graphics/internet-advertising-guru-sideh2-r.jpg); background-position:left; background-repeat:repeat-y;"><table width="230" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                          <td width="20"> </td>
                          <td width="200"><div align="center"><img src="internet-advertising-consultancy-graphics/internet-advertising-guru-top-rank-yahoo-msn.jpg" alt="We are Ranked Top "Internet Advertising Consultancy"! " title="We are Ranked Top "Internet Advertising Consultancy"! "/></div>
                          <div class="sideBlack">
                            <h1>We are Ranked Top "Internet Advertising Consultancy"!                            </h1>
                            <p>Google, Yahoo Asia and MSN have ranked Netbizsolutions.com as the top Internet Advertising Consultancy out of millions of other consultancies. We also have high standings for Internet Advertising Guru and Internet Advertising Consultant. We thank our competitors for making us better.</p>                          </div></td>
                          <td width="10"> </td>
                        </tr>
                      </table></td>
                    </tr>
                    <tr>
                      <td align="left" valign="top"><img src="internet-advertising-consultancy-graphics/internet-advertising-guru-foot.jpg" width="230" height="20" /></td>
                    </tr>
                </table></td>
              </tr>
          </table></td>
          <td width="550" align="left" valign="top"><table width="550" cellpadding="10">
            <tr><td><!-- InstanceBeginEditable name="EditRegion1" -->
		<h1>Contact Us</h1>
		<div align="center">
		<?
  if(!isset($_POST["hidFirstRun"])){
  fcCreateForm();//call function to create form
  }else{
  
  $validateResult=fcValidateData($_POST["txtName"],$_POST["txtEmail"],$_POST["txtPhone"]);
  
  if ($validateResult)//inputed data are valid
  {
  fcSendMail();//send mail
  }else{//inputed data are invalid or empty
  fcCreateForm($_POST["slTitle"],$_POST["txtName"],$_POST["txtCompanyName"],$_POST["txtPosition"],$_POST["taCompanyAddress"],$_POST["txtEmail"],$_POST["txtPhone"],$_POST["txtBusinessNature"],$_POST["txtCompanyHomepage"],$_POST["taComment"]);//call function to create form
  }
  
  }
  ?></div>

<br>
NetBizSolutions Services<br>
12-1, Jalan 5/109f,<br>
Plaza Danau 2, Taman Danau Desa,<br>
58100, Kuala Lumpur.<br>
<br>
Tel : 03-79808237<br>
<br>
<br>
View our Street map<br />
<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps/ms?hl=en&ie=UTF8&oe=UTF8&msa=0&msid=104091506452304834273.00046729040437617dfef&ll=3.099336,101.687179&spn=0.029997,0.036478&z=14&output=embed"></iframe><br /><br /><medium>View <a href="http://maps.google.com/maps/ms?hl=en&ie=UTF8&oe=UTF8&msa=0&msid=104091506452304834273.00046729040437617dfef&ll=3.099336,101.687179&spn=0.029997,0.036478&z=14&source=embed" style="color:#0000FF;text-align:left" target="_blank">NetBizSolutions.com</a> in a larger map</medium>     

<br>

<!-- Google Code for pageview Conversion Page -->
<script language="JavaScript" type="text/javascript">
<!--
var google_conversion_id = 1071839760;
var google_conversion_language = "en_US";
var google_conversion_format = "1";
var google_conversion_color = "000000";
if (1) {
  var google_conversion_value = 1;
}
var google_conversion_label = "pageview";
//-->
</script>
<script language="JavaScript" src="http://www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<img height=1 width=1 border=0 src="http://www.googleadservices.com/pagead/conversion/1071839760/imp.gif?value=1&label=pageview&script=0">
</noscript>
<br>
                                  







<!-- InstanceEndEditable --></td>
            </tr></table></td>
        </tr>
      </table></td>
    </tr>

    <tr>
      <td align="left" valign="top"><table width="780" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="220"> </td>
          <td width="20" align="left" valign="top"><img src="internet-advertising-consultancy-graphics/internet-advertising-guru-bottom1.jpg" width="20" height="15" /></td>
          <td width="530" style=" background-image:url(internet-advertising-consultancy-graphics/internet-advertising-guru-bottom1-r.jpg); background-position:top; background-repeat:repeat-x;"></td>
          <td width="10" align="right" valign="top"><img src="internet-advertising-consultancy-graphics/internet-advertising-guru-bottom2.jpg" width="10" height="15" /></td>
        </tr>




        	<tr>
	<td> 

	</td>
</tr>
        <tr>
          <td colspan="3" align="right"><div class="bottomLink">
            <a href="index.htm">Home</a>
            <a href="http://www.netbizasia.com/advertising.htm">Services</a>
            <a href="portfolio.html">Portfolio</a>
            <a href="news.html">News</a>
            <a href="location.htm">Location</a>
            <a href="contact.php">Contact Us</a>		 
      
            <a href="killer_internet_cashflow_strategies.html">Our Books</a> 
            <a href="workshops.html">Workshops</a> 
            <a href="malaysia-web-design.htm">Web Design</a> 
    <br>
   </td>
          <td width="10" align="right" valign="top"> </td>
        </tr>
        <tr>
          <td> </td>
          <td align="left" valign="top"> </td>
          <td align="right" valign="top"><div class="copyright">Copyright © 2001 Netbizsolutions Services</div></td>
          <td align="right" valign="top"> </td>
        </tr>
<tr>
	<td> 

	</td>
</tr>





      </table></td>
    </tr>
  </table>
  <div class="copyright"></div>
</div>
</body>
<!-- InstanceEnd --></html>

 

when i run this script and click on submit button ,the validation is working but it didn't direct me to the contact_success.php page.

Link to comment
https://forums.phpfreaks.com/topic/167452-solved-validation/#findComment-883186
Share on other sites

As its a long code to go through and check all. But i edited it where i think can do the job.

BTW where is your submit button?

You have a lot of code in one page. Why not break it and include it. It will reduce your headache.

 

<?php
function fcCreateForm($localTitle="Mr.",$localName="",$localCompanyName="",$localPosition="",$localCompanyAddress="",$localEmail="",$localPhone="",$localBusinessNature="",$localCompanyHomepage="http://",$localComment="")//this function create enquiry form
{

$localName=fcStringReplace($localName);
$localCompanyName=fcStringReplace($localCompanyName);
$localPosition=fcStringReplace($localPosition);
$localCompanyAddress=fcStringReplace($localCompanyAddress);
$localEmail=fcStringReplace($localEmail);
$localPhone=fcStringReplace($localPhone);
$localBusinessNature=fcStringReplace($localBusinessNature);
$localCompanyHomepage=fcStringReplace($localCompanyHomepage);
$localComment=fcStringReplace($localComment);

$arrayTitle=array("Mr.","Mrs.","Miss.","Mdm.");
$i=0;

echo "<form id='form1' name='form1' method='post' action=''>
<input type='hidden' name='hidFirstRun' value='no'/>
    <table width='400' border='0' cellspacing='0' cellpadding='6'>
      <tr>
        <td colspan='2' align='left' valign='top'><table width='400' border='0' cellspacing='0' style='padding-left:6px; padding-right:6px;'>
          <tr>
            <td width='100' align='right' valign='middle'>Title : </td>
            <td width='50'><select name='slTitle'>";
         
             while ($i < sizeof($arrayTitle))
{
echo "<option value='".$arrayTitle[$i]."'";
if ($arrayTitle[$i]==$localTitle)
{
echo "' selected='selected'>".$arrayTitle[$i]."";
}else{
echo "'>".$arrayTitle[$i]."";
}
echo "</option>";
$i++;
}
          
            echo "</select>
            </td>
            <td width='50' align='right' valign='middle'>Name : </td>
            <td width='200' align='left' valign='middle'><input type='text' name='txtName' value='".$localName."'/>
              <font color='#FF0000'>*</font></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td width='150' align='right' valign='middle'>Company Name : </td>
        <td width='250' align='left' valign='middle'><input type='text' name='txtCompanyName' style='width:60%;' value='".$localCompanyName."'/></td>
      </tr>
      <tr>
        <td width='150' align='right' valign='middle'>Position In Company : </td>
        <td width='250' align='left' valign='middle'><input type='text' name='txtPosition' value='".$localPosition."'/></td>
      </tr>
      <tr>
        <td width='150' align='right' valign='top'>Company Address : </td>
        <td width='250' align='left' valign='top'><textarea name='taCompanyAddress' rows='4' style='width:80%;'>".$localCompanyAddress."</textarea></td>
      </tr>
      <tr>
        <td align='right' valign='middle'>Email : </td>
        <td width='250' align='left' valign='middle'><input type='text' name='txtEmail' style='width:60%;' value='".$localEmail."'/>
          <font color='#FF0000'>*</font></td>
      </tr>
      <tr>
        <td width='150' align='right' valign='middle'>Phone : </td>
        <td width='250' align='left' valign='middle'><input type='text' name='txtPhone' style='width:60%;' value='".$localPhone."'/>
          <font color='#FF0000'>*</font></td>
      </tr>
      <tr>
        <td width='150' align='right' valign='middle'>Business Nature of Company : </td>
        <td width='250' align='left' valign='middle'><input type='text' name='txtBusinessNature' style='width:80%;' value='".$localBusinessNature."'/></td>
      </tr>
      <tr>
        <td align='right' valign='middle'>Company Homepage if any : </td>
        <td align='left' valign='middle'><input type='text' name='txtCompanyHomepage' style='width:80%;' value='".$localCompanyHomepage."'/></td>
      </tr>
      <tr>
        <td align='right' valign='top'>Your Requests or Comments : </td>
        <td align='left' valign='top'><textarea name='taComment' rows='10' style='width:100%;'>".$localComment."</textarea></td>
      </tr>
      <tr>
        <td align='right' valign='middle'> </td>
        <td align='left' valign='middle'><input type='submit' name='Submit' value='Send Enquiry' /></td>
      </tr>
    </table>
  </form>";
}//end of function

//function that validate inputed data
function fcValidateData($localName,$localEmail,$localPhone)
{
if(empty($localName) || empty($localEmail) || empty($localPhone))
{
if (empty($localName)){echo "<font color='red'>Please enter your name.</font><br/>";}
if (empty($localEmail)){echo "<font color='red'>Please enter your email.</font><br/>";}
if (empty($localPhone)){echo "<font color='red'>Please enter your phone number.</font><br/>";}
return false;
}else{
$validateEmail=fcEmailCheck($localEmail);
if ($validateEmail)//inputed email is in valid format
{
return true;
}else{//email address is invalid
echo "<font color='red'>Please enter a valid email address.</font>";
return false;
}
}
}//end of function

function fcEmailCheck($str) //email validation
{
$str = strtolower($str);
if(ereg("^([^[:space:]]+)@(.+)\.(ad|ae|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|cr|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|fi|fj|fk|fm|fo|fr|fx|ga|gb|gov|gd|ge|gf|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nato|nc|ne|net|nf|ng|ni|nl|no|np|nr|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$",$str)){
return true;//validate pass
} else {
return false;//validate fail
}

}//end of function

function fcStringReplace($localCheckMessage)
{
  $localCheckMessage=str_replace("\'","'",$localCheckMessage);
  $localCheckMessage=str_replace("\\\\","\\",$localCheckMessage);
$localCheckMessage=str_replace("\\\"",""",$localCheckMessage);
return $localCheckMessage;
  }//end of function

  function fcStringReplaceText($localCheckMessage)
{
  $localCheckMessage=str_replace("\'","'",$localCheckMessage);
  $localCheckMessage=str_replace("\\\\","\\",$localCheckMessage);
$localCheckMessage=str_replace("\\\"","\"",$localCheckMessage);
$localCheckMessage=str_replace("'","'",$localCheckMessage);
$localCheckMessage=str_replace(""","\"",$localCheckMessage);
return $localCheckMessage;
  }//end of function

  function fcSendMail()
{
//error_reporting(0);//turn off error report

require("rotator_config.php");
mysql_connect($databaseHost,$databaseUser,$databasePassword);//connect to mysql server
mysql_select_db($databaseName);//select database

$query="select count(*) as totalData from target";//query
$result=mysql_query($query);//retrieve data

while ($row=mysql_fetch_array($result))
{
$totalData=$row['totalData'];//get email total
}

$query="select count from rotate_count";
$result=mysql_query($query);

while ($row=mysql_fetch_array($result))
{
$offset=$row['count']-1;
$query="select target from target limit $offset,1";//query that retrieve email address
$result=mysql_query($query);

while ($row=mysql_fetch_array($result))
{
$recipient=$row['target'];
}
}

$localName=$_POST["slTitle"]." ".fcStringReplaceText($_POST["txtName"]);
$localCompanyName=fcStringReplaceText($_POST["txtCompanyName"]);
$localPosition=fcStringReplaceText($_POST["txtPosition"]);
$localCompanyAddress=fcStringReplaceText($_POST["taCompanyAddress"]);
$localEmail=$_POST["txtEmail"];
$localPhone=fcStringReplaceText($_POST["txtPhone"]);
$localBusinessNature=fcStringReplaceText($_POST["txtBusinessNature"]);
$localCompanyHomepage=fcStringReplaceText($_POST["txtCompanyHomepage"]);
$localComment=fcStringReplaceText($_POST["taComment"]);

//$recipient = "sean@netbizsolutions.com";//Mail send to
$subject = "NetBiz Solutions Enquiry";//Mail Subject
$mailheader = "From: $localEmail\n";
$mailheader .= "Reply-To: $localEmail\n";
$message  = "Name: $localName\n\n";
$message .= "Company Name: $localCompanyName\n\n";
$message .= "Position: $localPosition\n\n";
$message .= "Company Address: $localCompanyAddress\n\n";
$message .= "Email: $localEmail\n\n";
$message .= "Phone Number: $localPhone\n\n";
$message .= "Business Nature: $localBusinessNature\n\n";
$message .= "Company Homepage: $localCompanyHomepage\n\n";
$message .= "Message: $localComment";
$boolMailSent=@mail($recipient, $subject, $message, $mailheader);//sending mail

if ($boolMailSent==false) {
echo "<font color='red'>Sorry! Fail to deliver enquiry, please try again.</font>";
}else{
$offset=$offset+2;
if ($offset>$totalData){$offset=1;}
$query="update rotate_count set count=$offset";
$result=mysql_query($query);
if($result){
header ('location:contact_success.php');
}

}
} 

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/template_basic.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Internet Advertising Consultancy NetBizSolutions Internet Advertising Guru</title>
<META NAME="Keywords" CONTENT="Internet Advertising Consultancy, Internet Advertising Guru, Internet Advertising Consultants, Malaysia Web Design,Malaysia Web Hosting">
<META NAME="Description" CONTENT="NetBizSolutions, Your Internet Advertising Consultancy is led by Internet advertising Guru, Eugene Yeng. We specialize in Malaysia Web Design, Malaysia Web Hosting, Content Management systems and Internet Advertising.">
<META NAME="Copyright" CONTENT="Copyright © 2001 NetBizSolutions.com . All rights reserved">
<META NAME="Distribution" CONTENT="Global">
<META NAME="Rating" CONTENT="General">
<META NAME="Robots" CONTENT="All">
<META NAME="Revisit-After" CONTENT="7 Days">
<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
<script src="images/AC_RunActiveContent.js" type="text/javascript"></script>
<script src="images/AC_ActiveX.js" type="text/javascript"></script>
<link href="default.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div align="center">
  <table width="780" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td align="center" valign="top"><script type="text/javascript">
AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0','width','780','height','200','src','images/top','quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','images/top' ); //end AC code
</script><noscript><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="780" height="200">
        <param name="movie" value="images/top.swf" />
        <param name="quality" value="high" />
        <embed src="images/top.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="780" height="200"></embed>
      </object></noscript></td>
    </tr>
    <tr>
      <td align="left" valign="top"><script type="text/javascript">
AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0','width','780','height','30','src','images/nav','quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','images/nav' ); //end AC code
</script><noscript><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="780" height="30">
        <param name="movie" value="images/nav.swf" />
        <param name="quality" value="high" />
        <embed src="images/nav.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="780" height="30"></embed>
      </object></noscript></td>
    </tr>
    <tr>
      <td align="left" valign="top"><table width="780" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="230" align="left" valign="top" style="background-image:url(internet-advertising-consultancy-graphics/internet-advertising-guru-side-r.jpg); background-position:left; background-repeat:repeat-y;"><table width="230" border="0" cellspacing="0" cellpadding="0" >
              <tr>
                <td align="left" valign="top"><img src="internet-advertising-consultancy-graphics/internet-advertising-guru-logo.jpg" alt="internet advertising consultancy, NetBizSolutions company logo" width="230" height="140" title="internet advertising consultancy, NetBizSolutions company logo"/></td>
              </tr>
              <tr>
                <td><table width="230" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td align="left" valign="top"><img src="internet-advertising-consultancy-graphics/internet-advertising-guru-sideh1.jpg" width="230" height="25" /></td>
                    </tr>
                    <tr>
                      <td align="left" valign="top" style="background-image:url(internet-advertising-consultancy-graphics/internet-advertising-guru-sideh1-r.jpg); background-position:left; background-repeat:repeat-y;"><table width="230" border="0" cellspacing="0" cellpadding="0">
                       



         <tr>
                          <td width="20"> </td>
                         
         <td width="200"><div class="sideWhite">
                            <h1 align="left">What our clients say</h1>
         
            test
         </div></td>
                         
         <td width="10"> </td>
                       
         </tr>






                      </table></td>
                    </tr>
                    <tr>
                      <td align="left" valign="top"><img src="internet-advertising-consultancy-graphics/internet-advertising-guru-sideh2.jpg" width="230" height="20" /></td>
                    </tr>
                    <tr>
                      <td align="left" valign="top" style="background-image:url(internet-advertising-consultancy-graphics/internet-advertising-guru-sideh2-r.jpg); background-position:left; background-repeat:repeat-y;"><table width="230" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                          <td width="20"> </td>
                          <td width="200"><div align="center"><img src="internet-advertising-consultancy-graphics/internet-advertising-guru-top-rank-yahoo-msn.jpg" alt="We are Ranked Top "Internet Advertising Consultancy"! " title="We are Ranked Top "Internet Advertising Consultancy"! "/></div>
                          <div class="sideBlack">
                            <h1>We are Ranked Top "Internet Advertising Consultancy"!                            </h1>
                            <p>Google, Yahoo Asia and MSN have ranked Netbizsolutions.com as the top Internet Advertising Consultancy out of millions of other consultancies. We also have high standings for Internet Advertising Guru and Internet Advertising Consultant. We thank our competitors for making us better.</p>                          </div></td>
                          <td width="10"> </td>
                        </tr>
                      </table></td>
                    </tr>
                    <tr>
                      <td align="left" valign="top"><img src="internet-advertising-consultancy-graphics/internet-advertising-guru-foot.jpg" width="230" height="20" /></td>
                    </tr>
                </table></td>
              </tr>
          </table></td>
          <td width="550" align="left" valign="top"><table width="550" cellpadding="10">
            <tr><td><!-- InstanceBeginEditable name="EditRegion1" -->
         <h1>Contact Us</h1>
         <div align="center">
         <?
  if(!isset($_POST["hidFirstRun"])){
  fcCreateForm();//call function to create form
  }else{

  $validateResult=fcValidateData($_POST["txtName"],$_POST["txtEmail"],$_POST["txtPhone"]);

  if ($validateResult)//inputed data are valid
  {
  fcSendMail();//send mail
  }else{//inputed data are invalid or empty
  fcCreateForm($_POST["slTitle"],$_POST["txtName"],$_POST["txtCompanyName"],$_POST["txtPosition"],$_POST["taCompanyAddress"],$_POST["txtEmail"],$_POST["txtPhone"],$_POST["txtBusinessNature"],$_POST["txtCompanyHomepage"],$_POST["taComment"]);//call function to create form
  }

  }
  ?></div>

<br>
NetBizSolutions Services<br>
12-1, Jalan 5/109f,<br>
Plaza Danau 2, Taman Danau Desa,<br>
58100, Kuala Lumpur.<br>
<br>
Tel : 03-79808237<br>
<br>
<br>
View our Street map<br />
<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps/ms?hl=en&ie=UTF8&oe=UTF8&msa=0&msid=104091506452304834273.00046729040437617dfef&ll=3.099336,101.687179&spn=0.029997,0.036478&z=14&output=embed"></iframe><br /><br /><medium>View <a href="http://maps.google.com/maps/ms?hl=en&ie=UTF8&oe=UTF8&msa=0&msid=104091506452304834273.00046729040437617dfef&ll=3.099336,101.687179&spn=0.029997,0.036478&z=14&source=embed" style="color:#0000FF;text-align:left" target="_blank">NetBizSolutions.com</a> in a larger map</medium>     
       
<br>

<!-- Google Code for pageview Conversion Page -->
<script language="JavaScript" type="text/javascript">
<!--
var google_conversion_id = 1071839760;
var google_conversion_language = "en_US";
var google_conversion_format = "1";
var google_conversion_color = "000000";
if (1) {
  var google_conversion_value = 1;
}
var google_conversion_label = "pageview";
//-->
</script>
<script language="JavaScript" src="http://www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<img height=1 width=1 border=0 src="http://www.googleadservices.com/pagead/conversion/1071839760/imp.gif?value=1&label=pageview&script=0">
</noscript>
<br>
                                 







<!-- InstanceEndEditable --></td>
            </tr></table></td>
        </tr>
      </table></td>
    </tr>

    <tr>
      <td align="left" valign="top"><table width="780" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="220"> </td>
          <td width="20" align="left" valign="top"><img src="internet-advertising-consultancy-graphics/internet-advertising-guru-bottom1.jpg" width="20" height="15" /></td>
          <td width="530" style=" background-image:url(internet-advertising-consultancy-graphics/internet-advertising-guru-bottom1-r.jpg); background-position:top; background-repeat:repeat-x;"></td>
          <td width="10" align="right" valign="top"><img src="internet-advertising-consultancy-graphics/internet-advertising-guru-bottom2.jpg" width="10" height="15" /></td>
        </tr>




           <tr>
      <td> 
      
      </td>
   </tr>
        <tr>
          <td colspan="3" align="right"><div class="bottomLink">
            <a href="index.htm">Home</a>
            <a href="http://www.netbizasia.com/advertising.htm">Services</a>
            <a href="portfolio.html">Portfolio</a>
            <a href="news.html">News</a>
            <a href="location.htm">Location</a>
            <a href="contact.php">Contact Us</a>      
     
            <a href="killer_internet_cashflow_strategies.html">Our Books</a>
            <a href="workshops.html">Workshops</a>
            <a href="malaysia-web-design.htm">Web Design</a>
       <br>
      </td>
          <td width="10" align="right" valign="top"> </td>
        </tr>
        <tr>
          <td> </td>
          <td align="left" valign="top"> </td>
          <td align="right" valign="top"><div class="copyright">Copyright © 2001 Netbizsolutions Services</div></td>
          <td align="right" valign="top"> </td>
        </tr>
   <tr>
      <td> 
      
      </td>
   </tr>





      </table></td>
    </tr>
  </table>
  <div class="copyright"></div>
</div>
</body>
<!-- InstanceEnd --></html>

Link to comment
https://forums.phpfreaks.com/topic/167452-solved-validation/#findComment-883235
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.