Jump to content

"Contact Us" form validation not working


mikebyrne

Recommended Posts

I'm trying to get the form not to send unless the user includes there email address AND include some text in the "enquiry" box. At the moment the error message "Required fields are empty" appears when the submit button is pressed  :confused:

 

<?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">


<?php include ('inc_header.html'); ?>
<?php include ('inc_scrollingimages.html'); ?>
  <div id="boxesholder">
  <?php include ('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.php">
  



    <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>
<?php include ('inc_offers.html'); ?> 	
<?php include ('inc_footer.html'); ?> 
</body>
</html>

Link to comment
Share on other sites

You need to check that the enquiry field is not empty, just like the name and email.

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

 

It doesnt hurt to try a few things every now and then, its the best way to learn.

Link to comment
Share on other sites

When the 'Required fields' error shows up, you will need to determine which ones failed.

For example:

if ($_REQUEST['name'] == '') {
$nameError = 'Please enter a name';
}

and then put $nameError into the value of the "name" input.

 

However, this creates another issue, if a person were to just resubmit the form, it would be accepted because the name input has a value now.

Which means instead of checking for empty, you would also have to check for the error string.

 

The method I normally choose is to assign an "error" CSS class to the input, if an error on that input occurs.

Link to comment
Share on other sites

Where should the the below IF statement be located within the code?

 

if ($_REQUEST['name'] == '') {
$nameError = 'Please enter a name';
}

 

and is the below the correct way to code it?

 

<input name="name" type="text" class="formsingle" id="name" value = "$nameError"  />

 

Also, I'm not 100% sure what you mean by " "error" CSS class to the input,"

Link to comment
Share on other sites

The error variable doesn't need to be in the input.

<?PHP
if (!empty($_REQUEST['name']) {
$name=$_REQUEST['name'];
}
else{
$name=$_REQUEST['name'];
$nameError = 'Please enter a name';
}
?>

<?PHP IF (isset($nameError)){ echo "$nameError<br />"; } ?>
<strong>Name: </strong><br /><input name="name" type="text" class="formsingle" id="name" value="<?PHP IF (isset($name)){ echo "$name"; } ?>" />

Link to comment
Share on other sites

} else {
// Required field error
echo 'Required fields are empty';
// Lets fine out which one(s)
$nameError = ($_POST['name'] == '' ? true : false);
$emailError = ($_POST['name'] == '' ? true : false);
$enquiryError = ($_POST['name'] == '' ? true : false);
}

 

Now in your code you can do something like this

<input type="text" name="name" class="formsingle" id="name" value="<?php echo ($nameError ? 'Please enter a name' : ''); ?>" />

or

<input type="text" name="name" class="formsingle<?php echo ($nameError ? ' errorCSS' : ''); ?>" id="name" value="" />

 

You should also consider re-filling the fields when the form isnt submitted, I would hate to fill out an entire form, press submit and be told I missed 1 field and had to re-fill the whole form again.

Link to comment
Share on other sites

I'm looking for help with validating my "Contact Us" form. I want the form to be submitted only when the Name, Email and Enquiry fields are filled in. If they are not, I want the user to see what fields are missing.

 

At present my code looks like:

 

<?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'] != '' && trim($_REQUEST['enquiry']) != ''){


$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.byrnecomputingservices.ie/" );





}










$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 {



// Required field error



echo 'Required fields are empty';



// Lets fine out which one(s)



$nameError = ($_POST['name'] == '' ? true : false);



$emailError = ($_POST['name'] == '' ? true : false);



$enquiryError = ($_POST['name'] == '' ? true : false);
}

?>
<!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">


<?php include ('inc_header.html'); ?>
<?php include ('inc_scrollingimages.html'); ?>
  <div id="boxesholder">
  <?php include ('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.php">
  



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



      <input type="text" name="name" class="formsingle" id="name" value="<?php echo ($nameError ? 'Please enter a name' : ''); ?>" />
        <br />
        <br />
        <strong>Email:</strong><br />
        <input name="email" type="text" class="formsingle" id="emailaddress" value="<?php echo ($emailError ? 'Please enter an email Address' : ''); ?>" />
        <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>
<?php include ('inc_offers.html'); ?> 	
<?php include ('inc_footer.html'); ?> 
</body>
</html>

Link to comment
Share on other sites

Good point!

 

At the present the opening screen has "Required fields are empty" on the top screen and the two error messages "Please enter....." are displayed.

 

I presume the else statment is in the wrong place?

 

<?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'] != '' && trim($_REQUEST['enquiry']) != ''){


$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.byrnecomputingservices.ie/" );	

}

$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 {

// Required field error
echo 'Required fields are empty';

// Lets fine out which one(s)

$nameError = ($_POST['name'] == '' ? true : false);

$emailError = ($_POST['name'] == '' ? true : false);

$enquiryError = ($_POST['name'] == '' ? true : false);
}

?>
<!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">

<?php include ('inc_header.html'); ?>
<?php include ('inc_scrollingimages.html'); ?>
  <div id="boxesholder">
  <?php include ('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.php">

    <strong>Name: </strong><br />
      <input type="text" name="name" class="formsingle" id="name" value="<?php echo ($nameError ? 'Please enter a name' : ''); ?>" />
        <br />
        <br />
        <strong>Email:</strong><br />
        <input name="email" type="text" class="formsingle" id="emailaddress" value="<?php echo ($emailError ? 'Please enter an email Address' : ''); ?>" />
        <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>
<?php include ('inc_offers.html'); ?> 	
<?php include ('inc_footer.html'); ?> 
</body>
</html>

Link to comment
Share on other sites

I would add in a check either with the ereg (deprecated - should be using the preg family of functions) to see if all of the required values have been set before attempting to send the email.

 

If you want to keep it in your else, just put it in an if statement.  For example:

 

if ( isset ( $_POST [ 'button' ] ) ) 
{ 
    echo 'Required fields are empty'; 
    /* Extra code */
}

 

That said, you swap between $_POST and $_REQUEST.  I would make that consistent because you don't want some things coming from the URL or a cookie and others from $_POST.

 

~juddster

Link to comment
Share on other sites

1 - http://php.net/ereg - an old regular expression match (RTFM)

2 - It would either make your current else an else if OR it would just consume the body of your else statement

3 - They are automatically defined for you.  You just change the variable you are reading from, from $_REQUEST --> $_POST

 

else if ( isset ( $_POST [ 'button' ] )
{

    // Required field error
    echo 'Required fields are empty';

    // Lets fine out which one(s)
    $nameError = ($_POST['name'] == '' ? true : false);
    $emailError = ($_POST['name'] == '' ? true : false);
    $enquiryError = ($_POST['name'] == '' ? true : false);
}
else
{
    $nameError = false;
    $emailError = false;
    $enquiryError = false;
}

 

~juddster

Link to comment
Share on other sites

My code now 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;
}
// The form was submitted //
if (isset($_POST['button'])) {

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


$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.byrnecomputingservices.ie/" );	

}

$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 if ( isset ( $_POST [ 'button' ] )
{

    // Required field error
    echo 'Required fields are empty';

    // Lets fine out which one(s)
    $nameError = ($_POST['name'] == '' ? true : false);
    $emailError = ($_POST['name'] == '' ? true : false);
    $enquiryError = ($_POST['name'] == '' ? true : false);
}
else
{
    $nameError = false;
    $emailError = false;

?>
<!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">

<?php include ('inc_header.html'); ?>
<?php include ('inc_scrollingimages.html'); ?>
  <div id="boxesholder">
  <?php include ('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.php">

    <strong>Name: </strong><br />
      <input type="text" name="name" class="formsingle" id="name" value="<?php echo ($nameError ? 'Please enter a name' : ''); ?>" />
        <br />
        <br />
        <strong>Email:</strong><br />
        <input name="email" type="text" class="formsingle" id="emailaddress" value="<?php echo ($emailError ? 'Please enter an email Address' : ''); ?>" />
        <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>
<?php include ('inc_offers.html'); ?> 	
<?php include ('inc_footer.html'); ?> 
</body>
</html>

 

But it's throwing up syntax errors on lines 101 & 102

 

else if ( isset ( $_POST [ 'button' ] )
{

 

Line 112

else

 

And 285

 

<?php include ('inc_footer.html'); ?>

 

Any help on fixing this would be great!

Link to comment
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.