Jump to content

Recommended Posts

I'm looking for a bit of help introducing some validation into my "contact us" page. I'm looking to make the user have to enter an email address into textbox And something into the Enquiry box.

 

My 2 files are below:

 

 

contact-us.shtml

<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Byrne Computing Services</title>
<link href="styles.css" rel="stylesheet" type="text/css" />
<script src="SpryAssets/SpryMenuBar.js" type="text/javascript"></script>
<link href="SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="inc/jquery.js"></script>
<script type="text/javascript" src="inc/easySlider.js"></script>
<script type="text/javascript">
$(document).ready(function(){	
	$("#slider").easySlider();
});	
</script>
</head>

<body>
<div id="wrapper">
<!--#include file="inc_header.html" -->
  <!--#include file="inc_scrollingimages.html" -->
  <div id="boxesholder">
    <!--#include file="inc_specials.html" -->
  <div id="main">
    <div id="mainheader">
    	Contact Us</div>
  	<div id="maincontent2">
  	  <h2>Fill in the form below and we will contact you shortly.</h2>
  	  <p><img src="images/binarycode.jpg" alt="Binary Code" width="167" height="600" class="images" /><form id="form1" name="form1" method="post" action="mailer.php?mail=1">
  	    <strong>Name: </strong><br />
      <input name="name" type="text" class="formsingle" id="name" />
        <br />
        <br />
        <strong>Email:</strong><br />
        <input name="email" type="text" class="formsingle" id="emailaddress" />
        <br />
        <br />
        <strong>Interested in:</strong><br />
  	    <table border="0" cellspacing="0" cellpadding="0" class="table">
  	      <tr>
  	        <td class="interestedin"><strong>Computer Repair</strong></td>
  	        <td class="interestedin"><strong>Console Repair</strong></td>
  	        <td class="interestedin"><strong>Other Services</strong></td>
        </tr>
  	      <tr>
  	        <td class="interestedin">
  	          <input name="virusandmalwareremoval" type="checkbox" class="formcheckbox" id="virusandmalwareremoval" value="virusandmalwareremoval" />
  	          <label for="virusandmalwareremoval">Virus and Malware Removal</label>
  	        </td>
  	        <td class="interestedin">
  	          <input name="xbox360drivereplacement" type="checkbox" class="formcheckbox" id="xbox360drivereplacement" value="xbox360drivereplacement" />
              <label for="ps3drivereplacement">Xbox 360 Drive Replacement</label>
  	        </td>
  	        <td class="interestedin">
  	          <input name="databackup" type="checkbox" class="formcheckbox" id="databackup" value="databackup" />
              <label for="databackup">Data Backup</label>
  	        </td>
        </tr>
  	      <tr>
  	        <td class="interestedin">
  	          <input name="fullservice" type="checkbox" class="formcheckbox" id="fullservice" value="fullservice" />
              <label for="fullservice">Full Service</label>
  	        </td>
  	        <td class="interestedin">
  	          <input name="xbox360laserreplacement" type="checkbox" class="formcheckbox" id="xbox360laserreplacement" value="xbox360laserreplacement" />
              <label for="ps3laserreplacement">Xbox 360 Laser Replacement</label>
  	        </td>
  	        <td class="interestedin">
  	          <input name="websites" type="checkbox" class="formcheckbox" id="websites" value="websites" />
              <label for="websites">Web Design</label>
  	        </td>
        </tr>
  	      <tr>
  	        <td class="interestedin">
  	          <input name="quickfix" type="checkbox" class="formcheckbox" id="quickfix" value="quickfix" />
              <label for="quickfix">Quick Fix</label>
  	        </td>
  	        <td class="interestedin">
  	          <input name="xbox360rrodrepair" type="checkbox" class="formcheckbox" id="xbox360rrodrepair" value="xbox360rrodrepair" />
              <label for="ps3ylodrepair">Xbox 360 RROD Repair</label>
  	        </td>
  	        <td class="interestedin">
  	          <input name="datarecovery" type="checkbox" class="formcheckbox" id="datarecovery" value="datarecovery" />
              <label for="datarecovery">Data Recovery</label>
  	        </td>
        </tr>
  	      <tr>
  	        <td class="interestedin">
  	          <input name="upgrades" type="checkbox" class="formcheckbox" id="upgrades" value="upgrades" />
  	          <label for="upgrades">Upgrades</label>
          </td>
  	        <td class="interestedin"><input name="ps3drivereplacement" type="checkbox" class="formcheckbox" id="ps3drivereplacement" value="ps3drivereplacement" />
  	          <label for="ps3drivereplacement">PS3 Drive Replacement</label></td>
  	        <td class="interestedin">
  	          <input name="networkinstallation" type="checkbox" class="formcheckbox" id="networkinstallation" value="networkinstallation" />
  	          <label for="networkinstallation">Network Installation</label>
          </td>
        </tr>
  	      <tr>
  	        <td> </td>
  	        <td class="interestedin"><input name="ps3laserreplacement" type="checkbox" class="formcheckbox" id="ps3laserreplacement" value="ps3laserreplacement" />
  	        PS3
  	          <label for="ps3laserreplacement"> Laser Replacement</label></td>
  	        <td class="interestedin">
  	          <input name="mobilephoneissues" type="checkbox" class="formcheckbox" id="mobilephoneissues" value="mobilephoneissues" />
  	          <label for="mobilephoneissues">Mobile Phone Issues</label>
          </td>
        </tr>
  	      <tr>
  	        <td> </td>
  	        <td class="interestedin"><input name="ps3ylodrepair" type="checkbox" class="formcheckbox" id="ps3ylodrepair" value="ps3ylodrepair" />
  	          <label for="ps3ylodrepair">PS3 YLOD Repair</label></td>
  	        <td class="interestedin">
  	          <input name="emailconfiguration" type="checkbox" class="formcheckbox" id="emailconfiguration" value="emailconfiguration" />
  	          <label for="emailconfiguration">Email Configuration</label></td>
        </tr>
      </table>
  	    <br />
  	    
  	    <strong>Enquiry: </strong><br />
        <textarea name="enquiry" class="formmulti" id="enquiry"></textarea>
        <br />
        <br />
        <input type="submit" name="button" id="button" value="Submit" />
      </form>
      </p>
  	  
  	  <p><br />
    </p>
  	</div>
  </div>
</div>
  <!--#include file="inc_offers.html" -->
<!--#include file="inc_footer.html" -->
</body>
</html>

 

Mailer.php

<?php 
function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}

if (isset($_REQUEST['name'])) {

$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
  $enquiry = $_REQUEST['enquiry'] ;
if (isset($_REQUEST['virusandmalwareremoval'])){
	$virusandmalwareremoval = $_REQUEST['virusandmalwareremoval'] . "\n";
} else {
	$virusandmalwareremoval = "";
}
if (isset($_REQUEST['fullservice'])){
	$fullservice = $_REQUEST['fullservice'] . "\n";
} else {
	$fullservice = "";
}
if (isset($_REQUEST['quickfix'])){
	$quickfix = $_REQUEST['quickfix'] . "\n";
} else {
	$quickfix = "";
}
if (isset($_REQUEST['upgrades'])){
	$upgrades = $_REQUEST['upgrades'] . "\n";
} else {
	$upgrades = "";
}
if (isset($_REQUEST['xbox360drivereplacement'])){
	$xbox360drivereplacement = $_REQUEST['xbox360drivereplacement'] . "\n";
} else {
	$xbox360drivereplacement = "";
}
if (isset($_REQUEST['xbox360laserreplacement'])){
	$xbox360laserreplacement = $_REQUEST['xbox360laserreplacement'] . "\n";
} else {
	$xbox360laserreplacement = "";
}
if (isset($_REQUEST['xbox360rrodrepair'])){
	$xbox360rrodrepair = $_REQUEST['xbox360rrodrepair'] . "\n";
} else {
	$xbox360rrodrepair = "";
}
if (isset($_REQUEST['ps3drivereplacement'])){
	$ps3drivereplacement = $_REQUEST['ps3drivereplacement'] . "\n";
} else {
	$ps3drivereplacement = "";
}
if (isset($_REQUEST['ps3laserreplacement'])){
	$ps3laserreplacement = $_REQUEST['ps3laserreplacement'] . "\n";
} else {
	$ps3laserreplacement = "";
}
if (isset($_REQUEST['ps3ylodrepair'])){
	$ps3ylodrepair = $_REQUEST['ps3ylodrepair'] . "\n";
} else {
	$ps3ylodrepair = "";
}
if (isset($_REQUEST['databackup'])){
	$databackup = $_REQUEST['databackup'] . "\n";
} else {
	$databackup = "";
}
if (isset($_REQUEST['websites'])){
	$websites = $_REQUEST['websites'] . "\n";
} else {
	$websites = "";
}
if (isset($_REQUEST['datarecovery'])){
	$datarecovery = $_REQUEST['datarecovery'] . "\n";
} else {
	$datarecovery = "";
}
if (isset($_REQUEST['networkinstallation'])){
	$networkinstallation = $_REQUEST['networkinstallation'] . "\n";
} else {
	$networkinstallation = "";
}
if (isset($_REQUEST['mobilephoneissues'])){
	$mobilephoneissues = $_REQUEST['mobilephoneissues'] . "\n";
} else {
	$mobilephoneissues = "";
}
if (isset($_REQUEST['emailconfiguration'])){
	$emailconfiguration = $_REQUEST['emailconfiguration'] . "\n";
} else {
	$emailconfiguration = "";
}

if ( ereg( "[\r\n]", $name ) || ereg( "[\r\n]", $email ) ) {

header( "Location: http://www.parkersmedia.com/byrne" );

}
$mailcontent = "Name: ".$name;
$mailcontent.= "\n\nEmail: ".$email;
$mailcontent.= "\n\nInterested in: \n". $virusandmalwareremoval . $fullservice . $quickfix . $upgrades . $xbox360drivereplacement . $xbox360laserreplacement . $xbox360rrodrepair . $ps3drivereplacement . $ps3laserreplacement . $ps3ylodrepair . $databackup . $websites . $datarecovery . $networkinstallation . $mobilephoneissues . $emailconfiguration;
$mailcontent.= "\n\nEnquiry: " . $enquiry;

mail( "info@byrnecomputingservices.ie", "Enquiry from Byrne Computing Services",
    "$mailcontent", "From: $name <$email>" );
}
header( "Location: http://www.parkersmedia.com/byrne/thankyou.shtml" );	
?>

 

Any help on this would be great!

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

You need to make sure that both fields are set and that they both contain valid data.

if (isset($_REQUEST['name']) && $_REQUEST['name'] != '' && isset($_REQUEST['email']) && $_REQUEST['email'] != '') {

You should also check the validity of the email address.

Link to comment
https://forums.phpfreaks.com/topic/248226-validation-help/#findComment-1274675
Share on other sites

You could place that in a couple of places in your code, but the easiest place would probably be to wrap that if statement around your mail(...) statement. IE

if (... the if statement provided by buddski ...){
mail(... your arguments here ...);
}

 

Also, if you are interested, I wrote a tutorial on validation in PHP, which you can read here: http://blackscorner.me/2011/07/28/when-and-how-to-validate-your-php-variables/

 

There are actually two parts of that tutorial, the second deals with sanitization: http://blackscorner.me/2011/08/04/when-and-how-to-sanitize-your-php-variables/

 

They aren't the end all be all of tutorials on this subject, but its a fairly straight forward introduction

Link to comment
https://forums.phpfreaks.com/topic/248226-validation-help/#findComment-1274709
Share on other sites

Like this?

 


if ((isset($_REQUEST['name']) && $_REQUEST['name'] != '' && isset($_REQUEST['email']) && $_REQUEST['email'] != ''){
mail( "info@byrnecomputingservices.ie", "Enquiry from Byrne Computing Services",
    "$mailcontent", "From: $name <$email>" );
}
header( "Location: http://www.parkersmedia.com/byrne/thankyou.shtml" );

Link to comment
https://forums.phpfreaks.com/topic/248226-validation-help/#findComment-1274764
Share on other sites

Thats about right yes. You probably only want to redirect when you successfully send mail, otherwise the user may be redirected and think their mail was sent when it wasn't.

 

if ((isset($_REQUEST['name']) && $_REQUEST['name'] != '' && isset($_REQUEST['email']) && $_REQUEST['email'] != ''){
if(mail( "info@byrnecomputingservices.ie", "Enquiry from Byrne Computing Services", "$mailcontent", "From: $name <$email>" )) 
              header( "Location: http://www.parkersmedia.com/byrne/thankyou.shtml" );
        else 
              echo("Could not send mail");
}

Added the if-else around the mail function just in case the mail function fails (which happens sometimes, even if the $_REQUEST info passes the validation).

 

Link to comment
https://forums.phpfreaks.com/topic/248226-validation-help/#findComment-1274860
Share on other sites

And just because I have a scary love for arrays, you can clean up your large amount if elses with this

$fun = array(
	'virusandmalwareremoval',
	'fullservice',
	'quickfix',
	'upgrade',
	'xbox360drivereplacement',
	'xbox360laserreplacement',
	'xbox360rrodrepair',
	'ps3drivereplacement',
	'ps3laserreplacement',
	'ps3ylodrepair',
	'databackup',
	'websites . $datarecovery',
	'networkinstallation',
	'mobilephoneissues',
	'emailconfiguration'
);

foreach ($fun as $value) {
	${$value} = (isset($_REQUEST[$value]) ? $value . "\n" : '');
}

 

And because I am avoiding cleaning my house..

<?php 
function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}

if ((isset($_REQUEST['name']) && $_REQUEST['name'] != '' && isset($_REQUEST['email']) && $_REQUEST['email'] != ''){
$fun = array(
	'virusandmalwareremoval',
	'fullservice',
	'quickfix',
	'upgrade',
	'xbox360drivereplacement',
	'xbox360laserreplacement',
	'xbox360rrodrepair',
	'ps3drivereplacement',
	'ps3laserreplacement',
	'ps3ylodrepair',
	'databackup',
	'websites . $datarecovery',
	'networkinstallation',
	'mobilephoneissues',
	'emailconfiguration'
);

foreach ($fun as $value) {
	${$value} = (isset($_REQUEST[$value]) ? $value . "\n" : '');
}

$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$enquiry = $_REQUEST['enquiry'];

if (ereg("[\r\n]", $name) || ereg("[\r\n]", $email)) {
	header( "Location: http://www.parkersmedia.com/byrne" );
}
$mailcontent = "Name: ".$name;
$mailcontent.= "\n\nEmail: ".$email;
$mailcontent.= "\n\nInterested in: \n". $virusandmalwareremoval . $fullservice . $quickfix . $upgrades . $xbox360drivereplacement . $xbox360laserreplacement . $xbox360rrodrepair . $ps3drivereplacement . $ps3laserreplacement . $ps3ylodrepair . $databackup . $websites . $datarecovery . $networkinstallation . $mobilephoneissues . $emailconfiguration;
$mailcontent.= "\n\nEnquiry: " . $enquiry;

if (mail( "info@byrnecomputingservices.ie", "Enquiry from Byrne Computing Services","$mailcontent", "From: $name <$email>" )) {
	header( "Location: http://www.parkersmedia.com/byrne/thankyou.shtml" );	
} else {
	echo 'Mail not sent';
}
} else {
echo 'Required fields are empty';
}

?>

Link to comment
https://forums.phpfreaks.com/topic/248226-validation-help/#findComment-1274865
Share on other sites

I'm not 100% sure how to code the page to post to itself. Does it involve changing

 

<input type="submit" name="button" id="button" value="Submit" />

 

The commbined code looks like this:

 

<?php 
function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}

if (isset($_REQUEST['name']) && $_REQUEST['name'] != '' && isset($_REQUEST['email']) && $_REQUEST['email'] != ''){



$fun = array(





'virusandmalwareremoval',





'fullservice',





'quickfix',





'upgrade',





'xbox360drivereplacement',





'xbox360laserreplacement',





'xbox360rrodrepair',





'ps3drivereplacement',





'ps3laserreplacement',





'ps3ylodrepair',





'databackup',





'websites . $datarecovery',





'networkinstallation',





'mobilephoneissues',





'emailconfiguration'



);






foreach ($fun as $value) {





${$value} = (isset($_REQUEST[$value]) ? $value . "\n" : '');



}






$name = $_REQUEST['name'];



$email = $_REQUEST['email'];



$enquiry = $_REQUEST['enquiry'];






if (ereg("[\r\n]", $name) || ereg("[\r\n]", $email)) {





header( "Location: http://www.parkersmedia.com/byrne" );



}



$mailcontent = "Name: ".$name;



$mailcontent.= "\n\nEmail: ".$email;



$mailcontent.= "\n\nInterested in: \n". $virusandmalwareremoval . $fullservice . $quickfix . $upgrades . $xbox360drivereplacement . $xbox360laserreplacement . $xbox360rrodrepair . $ps3drivereplacement . $ps3laserreplacement . $ps3ylodrepair . $databackup . $websites . $datarecovery . $networkinstallation . $mobilephoneissues . $emailconfiguration;



$mailcontent.= "\n\nEnquiry: " . $enquiry;








if (mail( "info@byrnecomputingservices.ie", "Enquiry from Byrne Computing Services","$mailcontent", "From: $name <$email>" )) {





header( "Location: http://www.parkersmedia.com/byrne/thankyou.shtml" );






} else {





echo 'Mail not sent';



}
} else {



echo 'Required fields are empty';
}




?>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Byrne Computing Services</title>
<link href="styles.css" rel="stylesheet" type="text/css" />
<script src="SpryAssets/SpryMenuBar.js" type="text/javascript"></script>
<link href="SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="inc/jquery.js"></script>
<script type="text/javascript" src="inc/easySlider.js"></script>
<script type="text/javascript">
$(document).ready(function(){	
	$("#slider").easySlider();
});	
</script>
</head>

<body>
<div id="wrapper">
<!--#include file="inc_header.html" -->
  <!--#include file="inc_scrollingimages.html" -->
  <div id="boxesholder">
    <!--#include file="inc_specials.html" -->
  <div id="main">
    <div id="mainheader">
    	Contact Us</div>
  	<div id="maincontent2">
  	  <h2>Fill in the form below and we will contact you shortly.</h2>
  	  <p><img src="images/binarycode.jpg" alt="Binary Code" width="167" height="600" class="images" /><form id="form1" name="form1" method="post" action="mailer.php?mail=1">
  	    <strong>Name: </strong><br />
      <input name="name" type="text" class="formsingle" id="name" />
        <br />
        <br />
        <strong>Email:</strong><br />
        <input name="email" type="text" class="formsingle" id="emailaddress" />
        <br />
        <br />
        <strong>Interested in:</strong><br />
  	    <table border="0" cellspacing="0" cellpadding="0" class="table">
  	      <tr>
  	        <td class="interestedin"><strong>Computer Repair</strong></td>
  	        <td class="interestedin"><strong>Console Repair</strong></td>
  	        <td class="interestedin"><strong>Other Services</strong></td>
        </tr>
  	      <tr>
  	        <td class="interestedin">
  	          <input name="virusandmalwareremoval" type="checkbox" class="formcheckbox" id="virusandmalwareremoval" value="virusandmalwareremoval" />
  	          <label for="virusandmalwareremoval">Virus and Malware Removal</label>
  	        </td>
  	        <td class="interestedin">
  	          <input name="xbox360drivereplacement" type="checkbox" class="formcheckbox" id="xbox360drivereplacement" value="xbox360drivereplacement" />
              <label for="ps3drivereplacement">Xbox 360 Drive Replacement</label>
  	        </td>
  	        <td class="interestedin">
  	          <input name="databackup" type="checkbox" class="formcheckbox" id="databackup" value="databackup" />
              <label for="databackup">Data Backup</label>
  	        </td>
        </tr>
  	      <tr>
  	        <td class="interestedin">
  	          <input name="fullservice" type="checkbox" class="formcheckbox" id="fullservice" value="fullservice" />
              <label for="fullservice">Full Service</label>
  	        </td>
  	        <td class="interestedin">
  	          <input name="xbox360laserreplacement" type="checkbox" class="formcheckbox" id="xbox360laserreplacement" value="xbox360laserreplacement" />
              <label for="ps3laserreplacement">Xbox 360 Laser Replacement</label>
  	        </td>
  	        <td class="interestedin">
  	          <input name="websites" type="checkbox" class="formcheckbox" id="websites" value="websites" />
              <label for="websites">Web Design</label>
  	        </td>
        </tr>
  	      <tr>
  	        <td class="interestedin">
  	          <input name="quickfix" type="checkbox" class="formcheckbox" id="quickfix" value="quickfix" />
              <label for="quickfix">Quick Fix</label>
  	        </td>
  	        <td class="interestedin">
  	          <input name="xbox360rrodrepair" type="checkbox" class="formcheckbox" id="xbox360rrodrepair" value="xbox360rrodrepair" />
              <label for="ps3ylodrepair">Xbox 360 RROD Repair</label>
  	        </td>
  	        <td class="interestedin">
  	          <input name="datarecovery" type="checkbox" class="formcheckbox" id="datarecovery" value="datarecovery" />
              <label for="datarecovery">Data Recovery</label>
  	        </td>
        </tr>
  	      <tr>
  	        <td class="interestedin">
  	          <input name="upgrades" type="checkbox" class="formcheckbox" id="upgrades" value="upgrades" />
  	          <label for="upgrades">Upgrades</label>
          </td>
  	        <td class="interestedin"><input name="ps3drivereplacement" type="checkbox" class="formcheckbox" id="ps3drivereplacement" value="ps3drivereplacement" />
  	          <label for="ps3drivereplacement">PS3 Drive Replacement</label></td>
  	        <td class="interestedin">
  	          <input name="networkinstallation" type="checkbox" class="formcheckbox" id="networkinstallation" value="networkinstallation" />
  	          <label for="networkinstallation">Network Installation</label>
          </td>
        </tr>
  	      <tr>
  	        <td> </td>
  	        <td class="interestedin"><input name="ps3laserreplacement" type="checkbox" class="formcheckbox" id="ps3laserreplacement" value="ps3laserreplacement" />
  	        PS3
  	          <label for="ps3laserreplacement"> Laser Replacement</label></td>
  	        <td class="interestedin">
  	          <input name="mobilephoneissues" type="checkbox" class="formcheckbox" id="mobilephoneissues" value="mobilephoneissues" />
  	          <label for="mobilephoneissues">Mobile Phone Issues</label>
          </td>
        </tr>
  	      <tr>
  	        <td> </td>
  	        <td class="interestedin"><input name="ps3ylodrepair" type="checkbox" class="formcheckbox" id="ps3ylodrepair" value="ps3ylodrepair" />
  	          <label for="ps3ylodrepair">PS3 YLOD Repair</label></td>
  	        <td class="interestedin">
  	          <input name="emailconfiguration" type="checkbox" class="formcheckbox" id="emailconfiguration" value="emailconfiguration" />
  	          <label for="emailconfiguration">Email Configuration</label></td>
        </tr>
      </table>
  	    <br />
  	    
  	    <strong>Enquiry: </strong><br />
        <textarea name="enquiry" class="formmulti" id="enquiry"></textarea>
        <br />
        <br />
        <input type="submit" name="button" id="button" value="Submit" />
      </form>
      </p>
  	  
  	  <p><br />
    </p>
  	</div>
  </div>
</div>
  <!--#include file="inc_offers.html" -->
<!--#include file="inc_footer.html" -->
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/248226-validation-help/#findComment-1274881
Share on other sites

If changed it to

 

<form id="form1" name="form1" method="post" action="contact-us.html">

 

I'm not sure what you mean by

 

"You and do this by checking for the $_POST of your submit button."

 

<input type="submit" name="button" id="button" value="Submit" />

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/248226-validation-help/#findComment-1274887
Share on other sites

You can check that the form is submitted :)

<?php

function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
	$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
	$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
// The form was submitted //
if (isset($_POST['button'])) {
if (isset($_REQUEST['name']) && $_REQUEST['name'] != '' && isset($_REQUEST['email']) && $_REQUEST['email'] != ''){

	$fun = array(
		'virusandmalwareremoval',
		'fullservice',
		'quickfix',
		'upgrade',
		'xbox360drivereplacement',
		'xbox360laserreplacement',
		'xbox360rrodrepair',
		'ps3drivereplacement',
		'ps3laserreplacement',
		'ps3ylodrepair',
		'databackup',
		'websites',
		'datarecovery',
		'networkinstallation',
		'mobilephoneissues',
		'emailconfiguration'
	);

	foreach ($fun as $value) {
		${$value} = (isset($_REQUEST[$value]) ? $value . "\n" : '');
	}
	$name = $_REQUEST['name'];
	$email = $_REQUEST['email'];
	$enquiry = $_REQUEST['enquiry'];

	if (ereg("[\r\n]", $name) || ereg("[\r\n]", $email)) {
		header( "Location: http://www.parkersmedia.com/byrne" );
	}

	$mailcontent = "Name: ".$name;
	$mailcontent.= "\n\nEmail: ".$email;
	$mailcontent.= "\n\nInterested in: \n". $virusandmalwareremoval . $fullservice . $quickfix . $upgrades . $xbox360drivereplacement . $xbox360laserreplacement . $xbox360rrodrepair . $ps3drivereplacement . $ps3laserreplacement . $ps3ylodrepair . $databackup . $websites . $datarecovery . $networkinstallation . $mobilephoneissues . $emailconfiguration;
	$mailcontent.= "\n\nEnquiry: " . $enquiry;
	if (mail( "info@byrnecomputingservices.ie", "Enquiry from Byrne Computing Services","$mailcontent", "From: $name <$email>" )) {
		header( "Location: http://www.parkersmedia.com/byrne/thankyou.shtml" );
	} else {
		$message = 'Mail not sent';
	}
} else {
	$message = 'Required fields are empty';
}
}

?>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Byrne Computing Services</title>
<link href="styles.css" rel="stylesheet" type="text/css" />
<script src="SpryAssets/SpryMenuBar.js" type="text/javascript"></script>
<link href="SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="inc/jquery.js"></script>
<script type="text/javascript" src="inc/easySlider.js"></script>
<script type="text/javascript">
$(document).ready(function(){	
	$("#slider").easySlider();
});	
</script>
</head>

<body>
<div id="wrapper">
<!--#include file="inc_header.html" -->
  <!--#include file="inc_scrollingimages.html" -->
  <div id="boxesholder">
    <!--#include file="inc_specials.html" -->
  <div id="main">
    <div id="mainheader">
    	Contact Us</div>
  	<div id="maincontent2">
  	  <h2>Fill in the form below and we will contact you shortly.</h2>
  	  <p><img src="images/binarycode.jpg" alt="Binary Code" width="167" height="600" class="images" /><form id="form1" name="form1" method="post" action="mailer.php?mail=1">
  	    <strong>Name: </strong><br />
      <input name="name" type="text" class="formsingle" id="name" />
        <br />
        <br />
        <strong>Email:</strong><br />
        <input name="email" type="text" class="formsingle" id="emailaddress" />
        <br />
        <br />
        <strong>Interested in:</strong><br />
  	    <table border="0" cellspacing="0" cellpadding="0" class="table">
  	      <tr>
  	        <td class="interestedin"><strong>Computer Repair</strong></td>
  	        <td class="interestedin"><strong>Console Repair</strong></td>
  	        <td class="interestedin"><strong>Other Services</strong></td>
        </tr>
  	      <tr>
  	        <td class="interestedin">
  	          <input name="virusandmalwareremoval" type="checkbox" class="formcheckbox" id="virusandmalwareremoval" value="virusandmalwareremoval" />
  	          <label for="virusandmalwareremoval">Virus and Malware Removal</label>
  	        </td>
  	        <td class="interestedin">
  	          <input name="xbox360drivereplacement" type="checkbox" class="formcheckbox" id="xbox360drivereplacement" value="xbox360drivereplacement" />
              <label for="ps3drivereplacement">Xbox 360 Drive Replacement</label>
  	        </td>
  	        <td class="interestedin">
  	          <input name="databackup" type="checkbox" class="formcheckbox" id="databackup" value="databackup" />
              <label for="databackup">Data Backup</label>
  	        </td>
        </tr>
  	      <tr>
  	        <td class="interestedin">
  	          <input name="fullservice" type="checkbox" class="formcheckbox" id="fullservice" value="fullservice" />
              <label for="fullservice">Full Service</label>
  	        </td>
  	        <td class="interestedin">
  	          <input name="xbox360laserreplacement" type="checkbox" class="formcheckbox" id="xbox360laserreplacement" value="xbox360laserreplacement" />
              <label for="ps3laserreplacement">Xbox 360 Laser Replacement</label>
  	        </td>
  	        <td class="interestedin">
  	          <input name="websites" type="checkbox" class="formcheckbox" id="websites" value="websites" />
              <label for="websites">Web Design</label>
  	        </td>
        </tr>
  	      <tr>
  	        <td class="interestedin">
  	          <input name="quickfix" type="checkbox" class="formcheckbox" id="quickfix" value="quickfix" />
              <label for="quickfix">Quick Fix</label>
  	        </td>
  	        <td class="interestedin">
  	          <input name="xbox360rrodrepair" type="checkbox" class="formcheckbox" id="xbox360rrodrepair" value="xbox360rrodrepair" />
              <label for="ps3ylodrepair">Xbox 360 RROD Repair</label>
  	        </td>
  	        <td class="interestedin">
  	          <input name="datarecovery" type="checkbox" class="formcheckbox" id="datarecovery" value="datarecovery" />
              <label for="datarecovery">Data Recovery</label>
  	        </td>
        </tr>
  	      <tr>
  	        <td class="interestedin">
  	          <input name="upgrades" type="checkbox" class="formcheckbox" id="upgrades" value="upgrades" />
  	          <label for="upgrades">Upgrades</label>
          </td>
  	        <td class="interestedin"><input name="ps3drivereplacement" type="checkbox" class="formcheckbox" id="ps3drivereplacement" value="ps3drivereplacement" />
  	          <label for="ps3drivereplacement">PS3 Drive Replacement</label></td>
  	        <td class="interestedin">
  	          <input name="networkinstallation" type="checkbox" class="formcheckbox" id="networkinstallation" value="networkinstallation" />
  	          <label for="networkinstallation">Network Installation</label>
          </td>
        </tr>
  	      <tr>
  	        <td> </td>
  	        <td class="interestedin"><input name="ps3laserreplacement" type="checkbox" class="formcheckbox" id="ps3laserreplacement" value="ps3laserreplacement" />
  	        PS3
  	          <label for="ps3laserreplacement"> Laser Replacement</label></td>
  	        <td class="interestedin">
  	          <input name="mobilephoneissues" type="checkbox" class="formcheckbox" id="mobilephoneissues" value="mobilephoneissues" />
  	          <label for="mobilephoneissues">Mobile Phone Issues</label>
          </td>
        </tr>
  	      <tr>
  	        <td> </td>
  	        <td class="interestedin"><input name="ps3ylodrepair" type="checkbox" class="formcheckbox" id="ps3ylodrepair" value="ps3ylodrepair" />
  	          <label for="ps3ylodrepair">PS3 YLOD Repair</label></td>
  	        <td class="interestedin">
  	          <input name="emailconfiguration" type="checkbox" class="formcheckbox" id="emailconfiguration" value="emailconfiguration" />
  	          <label for="emailconfiguration">Email Configuration</label></td>
        </tr>
      </table>
  	    <br />
  	    
  	    <strong>Enquiry: </strong><br />
        <textarea name="enquiry" class="formmulti" id="enquiry"></textarea>
        <br />
        <br />
<?php echo (isset($message) ? $message : ''); ?>
        <input type="submit" name="button" id="button" value="Submit" />
      </form>
      </p>
  	  
  	  <p><br />
    </p>
  	</div>
  </div>
</div>
  <!--#include file="inc_offers.html" -->
<!--#include file="inc_footer.html" -->
</body>
</html>

Edit: I also placed your errors into a $message variable which is displayed in the HTML of the form if there is an error. Otherwise they will be thrown at the top of the script and be pointless :)

Link to comment
https://forums.phpfreaks.com/topic/248226-validation-help/#findComment-1274888
Share on other sites

Its posting to mailer.php instead of contact-us.shtml???

 

<?php

function curPageURL() {



$pageURL = 'http';



if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}



$pageURL .= "://";



if ($_SERVER["SERVER_PORT"] != "80") {





$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];



} else {





$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];



}



return $pageURL;
}
// The form was submitted //
if (isset($_POST['button'])) {



if (isset($_REQUEST['name']) && $_REQUEST['name'] != '' && isset($_REQUEST['email']) && $_REQUEST['email'] != ''){








$fun = array(







'virusandmalwareremoval',







'fullservice',







'quickfix',







'upgrade',







'xbox360drivereplacement',







'xbox360laserreplacement',







'xbox360rrodrepair',







'ps3drivereplacement',







'ps3laserreplacement',







'ps3ylodrepair',







'databackup',







'websites',







'datarecovery',







'networkinstallation',







'mobilephoneissues',







'emailconfiguration'





);










foreach ($fun as $value) {







${$value} = (isset($_REQUEST[$value]) ? $value . "\n" : '');





}





$name = $_REQUEST['name'];





$email = $_REQUEST['email'];





$enquiry = $_REQUEST['enquiry'];










if (ereg("[\r\n]", $name) || ereg("[\r\n]", $email)) {







header( "Location: http://www.parkersmedia.com/byrne" );





}










$mailcontent = "Name: ".$name;





$mailcontent.= "\n\nEmail: ".$email;





$mailcontent.= "\n\nInterested in: \n". $virusandmalwareremoval . $fullservice . $quickfix . $upgrades . $xbox360drivereplacement . $xbox360laserreplacement . $xbox360rrodrepair . $ps3drivereplacement . $ps3laserreplacement . $ps3ylodrepair . $databackup . $websites . $datarecovery . $networkinstallation . $mobilephoneissues . $emailconfiguration;





$mailcontent.= "\n\nEnquiry: " . $enquiry;





if (mail( "info@byrnecomputingservices.ie", "Enquiry from Byrne Computing Services","$mailcontent", "From: $name <$email>" )) {







header( "Location: http://www.parkersmedia.com/byrne/thankyou.shtml" );





} else {







echo 'Mail not sent';





}



} else {





echo 'Required fields are empty';



}
}

?>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Byrne Computing Services</title>
<link href="styles.css" rel="stylesheet" type="text/css" />
<script src="SpryAssets/SpryMenuBar.js" type="text/javascript"></script>
<link href="SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="inc/jquery.js"></script>
<script type="text/javascript" src="inc/easySlider.js"></script>
<script type="text/javascript">



$(document).ready(function(){








$("#slider").easySlider();



});




</script>
</head>

<body>
<div id="wrapper">



<!--#include file="inc_header.html" -->
  <!--#include file="inc_scrollingimages.html" -->
  <div id="boxesholder">
    <!--#include file="inc_specials.html" -->
  <div id="main">
    <div id="mainheader">
    



Contact Us</div>
  



<div id="maincontent2">
  



  <h2>Fill in the form below and we will contact you shortly.</h2>
  



  <p><img src="images/binarycode.jpg" alt="Binary Code" width="167" height="600" class="images" /><form id="form1" name="form1" method="post" action="contact-us.html">
  



    <strong>Name: </strong><br />



      <input name="name" type="text" class="formsingle" id="name" />
        <br />
        <br />
        <strong>Email:</strong><br />
        <input name="email" type="text" class="formsingle" id="emailaddress" />
        <br />
        <br />
        <strong>Interested in:</strong><br />
  



    <table border="0" cellspacing="0" cellpadding="0" class="table">
  



      <tr>
  



        <td class="interestedin"><strong>Computer Repair</strong></td>
  



        <td class="interestedin"><strong>Console Repair</strong></td>
  



        <td class="interestedin"><strong>Other Services</strong></td>



        </tr>
  



      <tr>
  



        <td class="interestedin">
  



          <input name="virusandmalwareremoval" type="checkbox" class="formcheckbox" id="virusandmalwareremoval" value="virusandmalwareremoval" />
  



          <label for="virusandmalwareremoval">Virus and Malware Removal</label>
  



        </td>
  



        <td class="interestedin">
  



          <input name="xbox360drivereplacement" type="checkbox" class="formcheckbox" id="xbox360drivereplacement" value="xbox360drivereplacement" />
              <label for="ps3drivereplacement">Xbox 360 Drive Replacement</label>
  



        </td>
  



        <td class="interestedin">
  



          <input name="databackup" type="checkbox" class="formcheckbox" id="databackup" value="databackup" />
              <label for="databackup">Data Backup</label>
  



        </td>



        </tr>
  



      <tr>
  



        <td class="interestedin">
  



          <input name="fullservice" type="checkbox" class="formcheckbox" id="fullservice" value="fullservice" />
              <label for="fullservice">Full Service</label>
  



        </td>
  



        <td class="interestedin">
  



          <input name="xbox360laserreplacement" type="checkbox" class="formcheckbox" id="xbox360laserreplacement" value="xbox360laserreplacement" />
              <label for="ps3laserreplacement">Xbox 360 Laser Replacement</label>
  



        </td>
  



        <td class="interestedin">
  



          <input name="websites" type="checkbox" class="formcheckbox" id="websites" value="websites" />
              <label for="websites">Web Design</label>
  



        </td>



        </tr>
  



      <tr>
  



        <td class="interestedin">
  



          <input name="quickfix" type="checkbox" class="formcheckbox" id="quickfix" value="quickfix" />
              <label for="quickfix">Quick Fix</label>
  



        </td>
  



        <td class="interestedin">
  



          <input name="xbox360rrodrepair" type="checkbox" class="formcheckbox" id="xbox360rrodrepair" value="xbox360rrodrepair" />
              <label for="ps3ylodrepair">Xbox 360 RROD Repair</label>
  



        </td>
  



        <td class="interestedin">
  



          <input name="datarecovery" type="checkbox" class="formcheckbox" id="datarecovery" value="datarecovery" />
              <label for="datarecovery">Data Recovery</label>
  



        </td>



        </tr>
  



      <tr>
  



        <td class="interestedin">
  



          <input name="upgrades" type="checkbox" class="formcheckbox" id="upgrades" value="upgrades" />
  



          <label for="upgrades">Upgrades</label>



          </td>
  



        <td class="interestedin"><input name="ps3drivereplacement" type="checkbox" class="formcheckbox" id="ps3drivereplacement" value="ps3drivereplacement" />
  



          <label for="ps3drivereplacement">PS3 Drive Replacement</label></td>
  



        <td class="interestedin">
  



          <input name="networkinstallation" type="checkbox" class="formcheckbox" id="networkinstallation" value="networkinstallation" />
  



          <label for="networkinstallation">Network Installation</label>



          </td>




        </tr>
  



      <tr>
  



        <td> </td>
  



        <td class="interestedin"><input name="ps3laserreplacement" type="checkbox" class="formcheckbox" id="ps3laserreplacement" value="ps3laserreplacement" />
  



        PS3
  



          <label for="ps3laserreplacement"> Laser Replacement</label></td>
  



        <td class="interestedin">
  



          <input name="mobilephoneissues" type="checkbox" class="formcheckbox" id="mobilephoneissues" value="mobilephoneissues" />
  



          <label for="mobilephoneissues">Mobile Phone Issues</label>



          </td>



        </tr>
  



      <tr>
  



        <td> </td>
  



        <td class="interestedin"><input name="ps3ylodrepair" type="checkbox" class="formcheckbox" id="ps3ylodrepair" value="ps3ylodrepair" />
  



          <label for="ps3ylodrepair">PS3 YLOD Repair</label></td>
  



        <td class="interestedin">
  



          <input name="emailconfiguration" type="checkbox" class="formcheckbox" id="emailconfiguration" value="emailconfiguration" />
  



          <label for="emailconfiguration">Email Configuration</label></td>



        </tr>



      </table>
  



    <br />
  



    
  



    <strong>Enquiry: </strong><br />
        <textarea name="enquiry" class="formmulti" id="enquiry"></textarea>
        <br />
        <br />
        <input type="submit" name="button" id="button" value="Submit" />
      </form>
      </p>
  



  
  



  <p><br />



    </p>
  



</div>
  </div>
</div>
  <!--#include file="inc_offers.html" -->



<!--#include file="inc_footer.html" -->
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/248226-validation-help/#findComment-1274889
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.