Jump to content

Seeing if this is a good way to accomplish this.


Matthew Herren

Recommended Posts

I have a form that when posted it submits to a data base and emails the results also. I was just wondering if this works, or if there's a better way this should be done.

 

the form coding.

<form name="auto1" method="post" class="beccas"  action="confirm.php" >
         <table width="600" border="0" cellpadding="0" cellspacin="0"  align="center" bgColor="#fff">
<tr>
<td colspan="3"><h2>Step 1. Contact Information</h2></td>
</tr><tr>
        <td colspan ="3"><div id='auto1_errorloc' class='error_messages'><span style color="#ff0000">&#8224;</span> Required Fields.</td>
</tr><tr>
         <td width="25%" align="left"><label class="description" for="element_5">Name&#8224; </label></td><td colspan="2"></td>
</tr><tr>
 <td width="33.3%" align="left"><input id="name" name= "name" class="element text" maxlength="255" size="14" value=""/></td>
         <td width="33.3%" align="left"><input id="last" name= "last" class="element text" maxlength="255" size="14" value=""/></td>
         <td width="33.3%" align="left"><input id="mi" name= "mi" class="element text" maxlength="1" size="2" value=""/></td>
</tr><tr>
 <td width="33.3%" align="left"><label class="description" for="name">First</label></td>
         <td width="33.3%" align="left"><label class="description" for="last">Last</label></td>
         <td width="33.3%" align="left"><label class="description" for="mi">M.I.</label></td>
</tr><tr>
<td width="50%" align="left"><input id="password" name="password" maxlength="9" size="15" value="" type="password"></td>
<td width="50%" align="left"><input id="password_confirm" name="password_confirm" maxlength="9"  size="15" value="" type="password"></td>
</tr><tr>
        <td width="50%" align="left"><label class="description" for="password">Password&#8224;</label></td>
        <td width="50%' align="left"><label class="description" for="password_confirm">Confirm Password&#8224;</label></td>
</tr><tr>
        <td colspan ="3"><label class="description" for="add">Address&#8224; </label></td>
</tr><tr>
        <td colspan ="3"><input id="add" name="add" class="element text large" value="" type="text"></td>
</tr><tr>
<td colspan ="3"><label class="description" for="add">Street Address</label></td>
</tr><tr>
        <td colspan ="3"><input id="city" name="city" class="element text large" value="" type="text"></td>
</tr><tr>
        <td colspan ="3"><label class="description" for="add2">City</label></td>
</tr><tr>
 <td width="33.3%" align="left"><input id="state" name= "state" class="element text" maxlength="255" size="14" value=""/></td>
         <td width="33.3%" align="left"><input id="zip" name= "zip" class="element text" maxlength="1" size="2" value=""/></td>
</tr><tr>
 <td width="50%" align="left"><label class="description" for="state">State</label></td>
 <td width="50%" align="left"><label class="description" for="zip">Zip Code</label></td>
</tr><tr>
         <td colspan ="3"><input id="email" name="email" class="element text large" size="100" maxlength="25" size="15" value="" type="email"></td>
</tr><tr>
         <td colspan ="3"><label class="description for="email">Email&#8224;</label></td>
</tr><tr>
 <td width="33.3%" align="left"><input id="hp" name= "hp" class="element text" maxlength="10" size="11" value=""/></td>
         <td width="33.3%" align="left"><input id="cp" name= "cp" class="element text" maxlength="10" size="11" value=""/></td>
         <td width="33.3%" align="left"><input id="work" name= "work" class="element text" maxlength="10" size="11" value=""/></td>
</tr><tr>
 <td width="33.3%" align="left"><label class="description" for="hp">Main Contact Number</label></td>
 <td width="33.3%" align="left"><label class="description" for="cp">Cell Phone</label></td>
 <td width="33.3%" align="left"><label class="description" for="element_3">Work Phone</label></td>
</tr><tr>
         <td colspan ="3"><label class="description" for="element_6"><hr /></label></td>
</tr><tr>
         <td colspan ="3"><label class="description" for="element_6">Vehicle Information</label></td>
</tr><tr>
         <td colspan ="3"><label class="description" for="element_6">Vehicle 1&#8224;</label></td>
</tr><tr>
          <td width="50%" align="left"><input id="make" name="make" class="element text medium" size="10" maxlength="20" value="" type="text"></td>
          <td width="50%" align="left"><input id="model" name="model" class="element text medium"  size="10" maxlength="20" value="" type="text"></td>
</tr><tr>
          <td width="50%" align="left"><label for="make">Make</label></td>
          <td width="50%" align="left"><label for="model">Model</label></td>
</tr><tr>
          <td width="50%" align="left"><input id="color" name="color" class="element text medium"  size="10" maxlength="10" value="" type="text"></td>
          <td width="50%" align="left"><input id="plate" name="plate" class="element text medium" maxlength="7" size="7" value="" type="text"></td>
</tr><tr>
         <td width="50%" align="left"><label for="element_1_3">Color</label></td>
         <td width="50%" align="left"><label for="element_1_4">Plate</label></td>
</tr><tr>
         <td colspan ="3"><label class="description" for="element_6">Vehicle 2&#8224;</label></td>
</tr><tr>
          <td width="50%" align="left"><input id="make2" name="make2" class="element text medium" size="10" maxlength="20" value="" type="text"></td>
          <td width="50%" align="left"><input id="model2" name="model2" class="element text medium"  size="10" maxlength="20" value="" type="text"></td>
</tr><tr>
          <td width="50%" align="left"><label for="make2">Make</label></td>
          <td width="50%" align="left"><label for="model2">Model</label></td>
</tr><tr>
          <td width="50%" align="left"><input id="color2" name="color2" class="element text medium"  size="10" maxlength="10" value="" type="text"></td>
          <td width="50%" align="left"><input id="plate2 name="plate2" class="element text medium" maxlength="7" size="7" value="" type="text"></td>
</tr><tr>
         <td width="50%" align="left"><label for="element_1_3">Color</label></td>
         <td width="50%" align="left"><label for="element_1_4">Plate</label></td>
</tr><tr>
         <td colspan ="3"><label class="description" for="element_6">Vehicle 3&#8224;</label></td>
</tr><tr>
          <td width="50%" align="left"><input id="make3" name="make3" class="element text medium" size="10" maxlength="20" value="" type="text"></td>
          <td width="50%" align="left"><input id="model3" name="model3" class="element text medium"  size="10" maxlength="20" value="" type="text"></td>
</tr><tr>
          <td width="50%" align="left"><label for="make3">Make</label></td>
          <td width="50%" align="left"><label for="model3">Model</label></td>
</tr><tr>
          <td width="50%" align="left"><input id="color3" name="color3" class="element text medium"  size="10" maxlength="10" value="" type="text"></td>
          <td width="50%" align="left"><input id="plate3" name="plate3" class="element text medium" maxlength="7" size="7" value="" type="text"></td>
</tr><tr>
         <td width="50%" align="left"><label for="element_1_3">Color</label></td>
         <td width="50%" align="left"><label for="element_1_4">Plate</label></td>
</tr><tr>
         <td colspan="3"><button type="reset" value="Reset">Reset</button><button type="submit" value="Submit">Submit</button></td>
</table>
</form>

confirm.php coding

<?php
include '/scripts/email.php';
include '/scripts/submit.php';

//check the fields to make sure their not empty
if (isset($_POST['name']) and ($_POST['name']<>''))
$name =($_POST['name']);
if (isset($_POST['last']) and ($_POST['last']<>''))
$last =($_POST['last']);
if (isset($_POST['mi']) and ($_POST['mi']<>''))
$mi =($_POST['mi']);

echo "Name: $last $name $mi<br />";

if (isset($_POST['add']) and ($_POST['add']<>''))
$add=($_POST['add']);
if (isset($_POST['add2']) and ($_POST['add2']<>''))
$add2 =($_POST['add2']);
if (isset($_POST['city']) and ($_POST['city']<>''))
$city =($_POST['city']);
if (isset($_POST['state']) and ($_POST['state']<>''))
$state =($_POST['state']);
if (isset($_POST['zip']) and ($_POST['zip']<>''))
$zip =($_POST['zip']);

echo "Address <br />";
echo " Line 1:$add <br />";
echo " Line 2:$add2 <br />";
echo "City:$city State:$state <br />";
echo "Zip:$zip <br />";

if (isset($_POST['email']) and ($_POST['email']<>''))
$email =($_POST['email']);

echo "Email: $email <br />";

if (isset($_POST['hp']) and ($_POST['hp']<>''))
$hp =($_POST['hp']);
if (isset($_POST['cp']) and ($_POST['cp']<>''))
$cp =($_POST['cp']);
if (isset($_POST['work']) and ($_POST['work']<>''))
$email =($_POST['work']);

echo "Phone&#40s&#41<br />";
echo "Home: $hp Cell: $cp Work: $work <br />";

if (isset($_POST['make']) and ($_POST['make']<>''))
$make =($_POST['make']);
if (isset($_POST['model']) and ($_POST['model']<>''))
$model =($_POST['model']);
if (isset($_POST['color']) and ($_POST['color']<>''))
$color =($_POST['color']);
if (isset($_POST['plate']) and ($_POST['plate']<>''))
$plate =($_POST['plate']);

else

$make="Please add at least one vehicle!";
$model="";
$color="";
$plate="";

if (isset($_POST['make2']) and ($_POST['make2']<>''))
$make2 =($_POST['make2']);
if (isset($_POST['model2']) and ($_POST['model2']<>''))
$model2 =($_POST['model2']);
if (isset($_POST['color2']) and ($_POST['color2']<>''))
$color2 =($_POST['color2']);
if (isset($_POST['plate2']) and ($_POST['plate2']<>''))
$plate2 =($_POST['plate2']);

else

$make2="";
$model2="";
$color2="";
$plate2="";


if (isset($_POST['make3']) and ($_POST['make3']<>''))
$make3 =($_POST['make3']);
if (isset($_POST['model3']) and ($_POST['model3']<>''))
$model3 =($_POST['model3']);
if (isset($_POST['color3']) and ($_POST['color3']<>''))
$color3 =($_POST['color3']);
if (isset($_POST['plate3']) and ($_POST['plate3']<>''))
$plate3 =($_POST['plate3']);

else

$make3="";
$model3="";
$color3="";
$plate3="";

echo "<hr /><br>";
?>

 

The email coding from the include.

<?php
if(!isset($_POST['submit']))
{

}
$name = ($_POST['name']);
$last = ($_POST['last']);
$mi = ($_POST['mi']);
$add = ($_POST['add']);
$add2 =($_POST['add2']);
$city =($_POST['city']);
$state =($_POST['state']);
$zip = ($_POST['zip']);
$email = ($_POST['email']);
$hp = ($_POST['hp']);
$cp = ($_POST['cp']);
$work = ($_POST['work']);
$make = ($_POST['make']);
$model = ($_POST['model']);
$color = ($_POST['color']);
$plate = ($_POST['plate']);
$make2 = ($_POST['make2']);
$model2 = ($_POST['model2']);
$color2 = ($_POST['color2']);
$plate2 = ($_POST['plate2']);
$make3 = ($_POST['make3']);
$model3 = ($_POST['model3']);
$color3 = ($_POST['color3']);
$plate3 = ($_POST['plate3']);
$password = ($_POST['password']);

//Validate first
if(empty($name)||empty($email)) 
{
    echo "Name and email are mandatory!";
    exit;
}

if(IsInjected($email))
{
    echo "Bad email value!";
    exit;
}

$email_from = 'www.beccastowing.com';//<== update the email address
$email_subject = "New Auto Club Submission";
$email_body = "$last, $name $mi has registered for Becca's Motor Club with the following information.
Name:$last, $name $mi
Address:$add
Line 2 :$add2
        $city $state $zip
Phone  :
Home :$hp Cell : $cp Work : $work
E-mail :#email
Vehicle 1
Make:$make Model:$model
Color:$color Plate:$plate
Vehicle 2
Make:$make2 Model:$model2
Color:$color2 Plate:$plate2
Vehicle 3
Make:$make3 Model:$model3
Color:$color3 Plate:$plate3
".
    
$to = "[email protected]";//<== update the email address
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $email \r\n";
//Send the email!
mail($to,$email_subject,$email_body,$headers);


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

 

On submition it call's the email.php and the submit.php.

The submit.php is just your simple submission script to a mysql data base that some of you have helped me figure out. Is this the correct way to do this. They both work so there's no errors.

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.