Jump to content

Validating forms, nothing returned. (Novice mistake i'm sure)


benprice

Recommended Posts

Hi all,

Just started on my first php project today, thinking it was gonna be extremely easy, for some silly reason.

Had previous experiance coding with html, css and javascript but still can't quite figure out what I have done wrong here.

 

Basically i've set up a html form to validate the entries by sending it to the php validation form. Using various sources on the internet and own intuitive thoughts.

 

After it sends to the php form it kept displaying errors on specific lines which i've managed to sort out. Now however, it comes back with a plain blank page.

 

I'm sure theres a really obvious reason why this wont work correctly but with my limited knowledge of PHP i'm not going to be ableto figure it out by myself before my assignments due in on friday.

 

The php code goes something like this:

 

<?php

$errormsg      = '';
$todate        = '';
$company       = '';
$contactname   = '';
$custnum       = '';
$emailadd      = '';
$ordernum      = '';
$telnum        = '';
$mobnum        = '';
$query         = '';
$house         = '';
$street        = '';
$addline1      = '';
$addline2      = '';
$county        = '';
$postcode      = '';
$delcharge     = '';
$typebuffet    = '';
$slunch        = '';
$crisps        = '';
$cans          = '';
$fruit         = '';
$totalbuslunch = '';
$qty           = '';
$totalcost     = '';
$deposit       = '';
$deldate       = '';
$comments      = '';

if(isset($POST['send']))
{
    $todate        = $POST['todate'];
    $company       = $POST['company'];
    $contactname   = $POST['contactname'];
    $custnum       = $POST['custnum'];
$emailadd      = $POST['emailadd'];
$ordernum      = $POST['ordernum'];
$telnum        = $POST['telnum'];
$mobnum        = $POST['mobnum'];
$query         = $POST['query'];
$house         = $POST['house'];
$street        = $POST['street'];
$addline1      = $POST['addline1'];
$addline2      = $POST['addline2'];
$county        = $POST['county'];
$postcode      = $POST['postcode'];
$delcharge     = $POST['delcharge'];
$typebuffet    = $POST['typebuffet'];
$slunch        = $POST['slunch'];
$crisps        = $POST['crisps'];
$cans          = $POST['cans'];
$fruit         = $POST['fruit'];
$totalbuslunch = $POST['totalbuslunch'];
$qty           = $POST['qty'];
$totalcost     = $POST['totalcost'];
$deposit       = $POST['deposit'];
$deldate       = $POST['deldate'];
$comments      = $POST['comments'];

if(trim($todate) == '')
{
   $errormsg = 'Please use the back button and enter todays date.';
}

if(trim($contactname) == '')
{
   $errormsg = 'Please use the back button and enter your contact name.';
}

if(!isEmail($emailadd) == '')
{
   $errormsg = 'Please use the back button and enter your E-Mail address.\r\n E.G. ???@???.co.uk';
}

if(trim($telnum) == '')
{
   $errormsg = 'Please use the back button and enter your 11 or 12 digit telephone number (Including Area Code).\r\n E.G. 01373826886';
}

if(trim($todate) == '')
{
   $errormsg = 'Please use the back button and enter todays date.';
}
  
  if($errormsg <> '')
  {
  echo "$errormsg";
  }

//Query if statement goes here

if(trim($query) == '-- Please Select --')
{
$errormsg = 'Please use the back button and select the type of query you would like to make';
}
else if(trim($query) == 'Buffet Order')
{
//Buffet order code goes here
if(trim($house) == '')
{$errormsg = 'Please use the back button and enter your house name or number.';}
else if(trim($street) == '')
{$errormsg = 'Please use the back button and enter the street that your house is located on.';}
else if(trim($addline1) == '')
{$errormsg = 'Please use the back button and enter the first line of the address that your house is located on.';}
else if(trim($county) == '')
{$errormsg = 'Please use the back button and enter the county that your house is located in.';}
else if(trim($postcode) == '')
{$errormsg = 'Please use the back button and enter the postcode of your house';}
else if(trim($delcharge) == '-- Please Select --')
{$errormsg = 'Please use the back button and select the delivery charge category you fall into. \r\n If you are not sure, please phone us on 01373826886';}
else if(trim($typebuffet) == '-- Please Select --')
{$errormsg = 'Please use the back button and enter the street that your house is located on.';}

  if($errormsg == '')
  {
     if(get_magic_quotes_gpc())
     {
        $company     = stripslashes($company);
        $contactname = stripslashes($contactname);
        $emailadd    = stripslashes($emailadd);
        $house       = stripslashes($house);
        $street      = stripslashes($street);
        $addline1    = stripslashes($addline1);
        $addline2    = stripslashes($addline2);
        $county      = stripslashes($county);
        $postcode    = stripslashes($postcode);
	$comments    = stripslashes($comments);
 }
  
  $to      = "???@???.co.uk";
  $subject = "[$query] - $contactname, $company";
  $msg     = "Date of Order: $todate \r\n Contact Name: $contactname \r\n Company: $company \r\n E-mail Address: $emailadd \r\n Telephone Number: $telnum \r\n Type of Query: $query \r\n Order Number: $ordernum \r\n Customer Number: $custnum \r\n House Name/Number: $house \r\n Street: $street \r\n Address Line 1: $addline1 \r\n Address Line 2: $addline2 \r\n County: $county \r\n Postcode: $postcode \r\n Delivery Charge: $delcharge \r\n Type of Buffet: $typebuffet \r\n Business Lunch Requirements: \r\n $slunch \r\n $crisps\r\n $cakes \r\n $cans \r\n $fruit \r\n Number of People: $people \r\n Total Cost: $totalcost \r\n Deposit: $deposit \r\n Delivery Date: $deldate \r\n \r\n Comments: \r\n $comments"; 
  
  mail($to,
       $subject,
   $msg,
   "From: $emailadd \r\n Return-Path: $emailadd \r\n ");
   
   header ("Location: http://www.???.co.uk/thankyou.htm");
   
  }
  
  if($errormsg <> '')
  {
  echo "$errormsg";
  }

//Buffet order code ends here
}
else if(trim($comment) == '')
{$errormsg = 'Please use the back button and enter a comment.';}
else if (trim($comment) == 'Please wite any comments you have here!')
{$errormsg = 'Please use the back button and enter a comment.';}

  if($errormsg == '')
  {
     if(get_magic_quotes_gpc())
     {
        $contactname = stripslashes($contactname);
        $emailadd    = stripslashes($emailadd);
	$company     = stripslashes($comments);
 }
  
  $to      = "???@???.co.uk";
  $subject = "[$query] - $contactname, $company";
  $msg     = "Date of Submission: $todate \r\n Contact Name: $contactname \r\n Company: $company \r\n E-mail Address: $emailadd \r\n Telephone Number: $telnum \r\n Mobile Number: $mobnum \r\n Type of Query: $query \r\n Order Number: $ordernum \r\n Customer Number: $custnum \r\n \r\n Comments: \r\n $comments"; 
  mail($to,
       $subject,
   $msg,
   "From: $emailadd \r\n Return-Path: $emailadd \r\n ");
   
   header ("Location: http://www.???.co.uk/thankyou.htm");
   }
  if($errormsg <> '')
  {
  echo "$errormsg";
  }
  
//Query if statement ends here
}
?>

 

 

The form that submits the data to it is

 

      <form action="verify.php" method="post" encType="text/plain" name="form" id="form">
  
        <Table width="95%" border=0 align="center" cellpadding="0" cellspacing="0">
          <tr> 

            <td colspan="4" align="center"><font color="#A23B00"><b><u>Visitor Details<br>
              <font color="#FFFFFF">k</font></u></b></font></td>
          </tr>
          <tr> 
            <td width="20%" align="right"><font color="#FF0000">*</font><font color="#A23B00">Todays Date:</font></td>
            <td width="30%" align="center" valign="middle"><font color="#A23B00">
              <input name="todate" type="text" id="todate" value="DDMMYYYY" maxlength="8">
            </font></td>
		<td width="20%" align="right"><font color="#A23B00">Company:</font></td>
            <td width="30%" align="center" valign="middle"><font color="#A23B00">
              <input name="company" type="text" id="company"></font></td>
          </tr>
          <tr> 
            <td width="20%" align="right"><font color="#FF0000">*</font><font color="#A23B00">Contact Name: </font></td>
            <td width="30%" align="center"><font color="#A23B00">
              <input name="contactname" type="text" id="contactname">
            </font></td>
		<td width="20%" align="right"><font color="#A23B00">Customer No.: </font></td>
            <td width="30%" align="center"><font color="#A23B00">
              <input name="custnum" type="text" id="custnum"></font></td>
          </tr>
          <tr> 
            <td width="20%" align="right"><font color="#FF0000">*</font><font color="#A23B00">E-mail Address:</font></td>
            <td width="30%" align="center"><font color="#A23B00"><input name="emailadd" type="text" id="emailadd"></font></td>
		<td width="20%" align="right"><font color="#A23B00">Order No.: </font></td>
            <td width="30%" align="center"><font color="#A23B00"><input name="ordernum" type="text" id="ordernum"></font></td>
          </tr>
	  <tr>
	     <td width="20%" align="right"><font color="#FF0000">*</font><font color="#A23B00">Telephone No.:</font></td>
             <td width="30%" align="center"><font color="#A23B00"><input type="text" name="telnum" id="telnum"></font></td>
		 <td width="20%" align="right"><font color="#A23B00">Mobile No.: </font></td>
             <td width="30%" align="center"><font color="#A23B00"><input name="mobnum" type="text" id="mobnum">
             </font></td>
	  </tr>
	  <tr>
	  <td colspan="2" align="right"><font color="#A23B00"><b><br>
	    <font color="#FF0000">*</font>Type of Query</b></font></td>
	  <td colspan="2" align="left"><font color="#A23B00"><br>
	   
	  <select name="query" id="query">
	    <option>Website Enquiry</option>
	    <option>Round Enquiry</option>
	    <option>Order</option>
	    <option>Administration</option>
	    <option>Other</option>
	    <option selected>-- Please Select --</option>
	    </select>
	  </font></td>
	  </tr>
	  <tr>
	    <td colspan="4" align="center"><font color="#A23B00"><b><u><br>
        Delivery Details </u></b>(If Applicable)</font></td>
	  </tr>
          <tr>
	    <td colspan="4" width="100%" align="center">
		 <table width="88%" cellpadding="0" cellspacing="0" border="0">
		 <tr>			 </tr>
		   <td colspan="2" align="left"><font color="#A23B00"><i><u>Address</u></i></font></td>
		 <tr>
		 <td width="50%" align="right"><font color="#FF0000">*</font><font color="#A23B00">House Name/No.</font></td>
		 <td width="50%" align="left"><font color="#FFFFFF">-</font><font color="#A23B00"> 
		   <input name="house" type="text" id="house">
		 </font>
		 <td>
		 </tr>
		 <tr>
		 <td width="50%" align="right"><font color="#FF0000">*</font><font color="#A23B00">Street:</font></td>
		 <td width="50%" align="left"><font color="#FFFFFF">-</font><font color="#A23B00"> 
		   <input name="street" type="text" id="street">
		 </font>
		 <td>
		 </tr>
		 <tr>
		 <td width="50%" align="right"><font color="#FF0000">*</font><font color="#A23B00">Address Line 1:</font></td>
		 <td width="50%" align="left"><font color="#FFFFFF">-</font><font color="#A23B00"> 
		   <input name="addline1" type="text" id="addline1">
		 </font>
		 <td>
		 </tr>
		 <tr>
		 <td width="50%" align="right"><font color="#A23B00">Address Line 2:</font></td>
		 <td width="50%" align="left"><font color="#FFFFFF">- 
		   </font><font color="#A23B00">
		   <input name="addline2" type="text" id="addline2">
		 </font>
		 <td>
		 </tr>
		 <tr>
		 <td width="50%" align="right"><font color="#FF0000">*</font><font color="#A23B00">County:</font></td>
		 <td width="50%" align="left"><font color="#FFFFFF">- 
		   </font><font color="#A23B00">
		   <input name="county" type="text" id="county">
		 </font>
		 <td>
		 </tr>
		 <tr>
		 <td width="50%" align="right"><font color="#FF0000">*</font><font color="#A23B00">Postcode:</font></td>
		 <td width="50%" align="left"><font color="#FFFFFF">-</font><font color="#A23B00"> 
		   <input name="postcode" type="text" id="postcode">
		 </font>
		 <td>
		 </tr>
		 <tr>
		 <td width="50%" align="right"><font color="#FF0000">*</font><font color="#A23B00">Delivery Charge</font></td>
		 <td width="50%" align="left"><font color="#FFFFFF">-</font><font color="#A23B00">
		   <select name="delcharge" id="delcharge">
		     <option selected>-- Please Select --</option>
		     <option>On Round - £0.00</option>
		     <option>UK - £5.00</option>
		     <option>Worldwide - £10.00</option>
		     <option>USA - £25.00</option>
		     </select></font></td>
		 </tr>
		 </table>
		 <br>
		 <table align="center" width="88%" cellpadding="0" cellspacing="0" border="0">
		 <tr>
		 <td colspan="2" align="left"><font color="#A23B00"><i><u>Order</u></i></font></td>
		 </tr>
		 <tr>
		 <td width="50%" align="right"><font color="#FF0000">*</font><font color="#A23B00">Type of Buffet<br>
		   <font color="#FFFFFF">k</font></font></td>
		 <td width="50%" align="left"><font color="#FFFFFF">- 
		   <select name="typebuffet" id="typebuffet">
		     <option>-- Please Select --</option>
		     <option>Business Lunch</option>
	                  <option>Saint</option>
		     <option>Brick</option>
		     <option>Cliff</option>
		     <option>Dome</option>
		     <option>Fountain</option>
		     <option>Corset</option>
		     <option>Room</option>
		     </select>
		   <br>
		 </font></td>
		 </tr>
		 <tr>
		 <td width="50%" align="right"><font color="#A23B00">Business Lunch Contents (If Applicable)<br>
		   <font color="#FFFFFF">K</font></font></td>
		 <td width="50%" align="left"><font color="#FFFFFF">-
		   <label>
		   <font color="#A23D00">
		   <input type="checkbox" name="slunch" value="Sandwich Lunch" checked>
		   Sandwich Lunch</font></label>
		   <br>
		   - 
		   <font color="#A23D00">
		   <label>
		   <input type="checkbox" name="crisps" value="Crisp Basket">
		   Crisp Basket </label>
		   </font>			 <br>
		 - 
		 <font color="#A23D00">
		 <label>
		 <input type="checkbox" name="cakes" value="Cakes">
		 Cakes</label>
		 </font>			 <br>
		 - 
		 <label>
		 <font color="#A23D00">
		 <input type="checkbox" name="cans" value="Cans">
		 Cans</font></label>
		 <br>
		 - 
		 <font color="#A23D00">
		 <label>
		 <input type="checkbox" name="fruit" value="Fruit Basket">
		 Fruit Basket</label>
		 </font></font><br>
		 </tr>
		 <tr>
		 <br>
		 <td> </td>
		 <td><div align="left"></div></td>
		 </tr>
		 <tr>
		 <td width="50%" align="right"><font color="#FF0000">*</font><font color="#A23B00">No. of People</font></td>
		 <td width="50%" align="left"><font color="#FFFFFF">- 
		   <input name="qty" type="text" id="qty">
		 </font></td>
		 </tr>
		 <tr>
		 <td width="50%" align="right"><font color="#FF0000">*</font><font color="#A23B00">Total Cost (£)</font></td>
		 <td width="50%" align="left"><font color="#FFFFFF">- 
		   <input name="totalcost" type="text" id="totalcost">
		 </font></td>
		 </tr>
		 <tr>
		 <td width="50%" align="right"><font color="#FF0000">*</font><font color="#A23B00">Deposit (20% of full price) (£)</font></td>
		 <td width="50%" align="left"><font color="#FFFFFF">- 
		     <input name="deposit" type="text" id="deposit">
		 </font></td>
		 </tr>
		 <tr>
		 <td width="50%" align="right"><font color="#FF0000">*</font><font color="#A23B00">Delivery Date</font></td>
		 <td width="50%" align="left"><font color="#FFFFFF">- 
		     <input name="deldate" type="text" id="deldate" maxlength="8">
		 </font></td>
		 </tr>
		 </table>
		 <br>
	     <table width="95%" border="0" cellspacing="0" cellpadding="0">
               <tr>
                 <td><font color="#A23D00" face="Arial"><u>Comments</u></font></td>
               </tr>
               <tr>
                 <td><div align="center">
                   <textarea name="comments" cols="70" rows="10" id="comments">Please wite any comments you have here!</textarea>
                 </div></td>
               </tr>
             </table>
	     <br>
	     <table width="50%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="50%"><div align="center">
                  <input type="submit" name="Submit" id="Submit" value="Submit" >
                </div></td>
                <td width="50%"><div align="center">
                  <input name="Reset" type="reset" id="Reset" value="Reset">
                </div></td>
              </tr>
            </table>
        <br></td>
	  </tr>
        </Table>
      </form>

 

 

And the only other page related to it is

 

<div align="center">
  <p>Thank you for contacting us,</p>
  <p>???</p>
  <p><a href="http://www.???.co.uk">Click Here to Continue Browsing Our Site! </a></p>
</div>

 

Hope theirs someone good enough to give me a hand,

Thanks for any advice!

Okay so i've sorted out *A* problem but its still not showing anything.

 

The problem that i've sorted was the $POST too $_POST.

 

Is there any chance that the echos are not in the right place?

 

Any help would be greatly appriciated!

 

hey man, try changing this:

 

if($errormsg <> '')

  {

  echo "$errormsg";

  }

 

to this:

 

if($errormsg != '')

  {

  echo "$errormsg";

  }

 

also...it doesn't look like the processing page is redirecting the confirmation page, but maybe i just didn't look closely enough.

 

 

 

also...you might wanna look at some tutorials about writing functions, they can really help

with structuring you're code and they make it aot easier for people to read your code. 

tizag.com and phpfreaks.com both have good stuff.

  • 1 month later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.