?
Solved

Help with form emailed through PHP with multiple inputs

Posted on 2008-10-08
16
Medium Priority
?
241 Views
Last Modified: 2010-04-21
I need to create sort of like an "order" form, except the users "order" is just emailed to myself.
We will have a list of items with checkboxes the user can click if they would like to add this to their "order". Beside the product I'd like to have a drop down menu for the quantity they'd like to order.

I can do forms but I am having difficulty with the use of multiple types of inputs.

--

Example:
Name: (text input required)
Email (text input required)
Site: (text input required)

Products:
Flyer One (Checkbox)
Quantity (drop down menu)

Poster One (Checkbox)
Quantity (drop down menu)

Tshirt One (Checkbox)
Quantity (drop down menu)

Submit

emailed through PHP to name@email.com

---

I am not using MySQL as I've had absoutely no experience with it.

I've created one form that semi-works, but if there is a checkbox left unchecked it throws an error on the "thanks" page.

I need help!!
0
Comment
Question by:natsully
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 6
16 Comments
 
LVL 82

Expert Comment

by:hielo
ID: 22670329
>>I've created one form that semi-works,
post what you have
0
 

Author Comment

by:natsully
ID: 22670564
it's pretty messy but i've been experimenting with it

this is the first page
<!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>Untitled Document</title>
<style type="text/css">
<!--
.style5 {font-size: 15px}
.style7 {font-family: Arial, Helvetica, sans-serif}
.style8 {font-size: 14px}
.style9 {font-family: Arial, Helvetica, sans-serif; font-size: 14px; }
.style11 {font-size: 15px; font-family: Arial, Helvetica, sans-serif; }
.style12 {font-weight: bold; font-size: 15px; font-family: Arial, Helvetica, sans-serif; }
-->
</style>
</head>
 
<body><form id="form1" name="form1" method="post" action="orderform_thanks.php">
<table width="888" border="0" align="left">
<tr>
    <th width="206" height="55" scope="row"><div align="left" class="style11">
      <label>
      <div align="left"><strong>Name:
        </strong>
        <input type="text" name="name" id="name" />
      </div>
      </label>
    </div></th>
    <td width="179"><div align="center"><span class="style7"><span class="style8"></span></span></div></td>
    <td width="230"><div align="center"><span class="style7"><span class="style8"></span></span></div></td>
    <td width="255"><div align="center"><span class="style7"><span class="style8"></span></span></div></td>
  </tr>
<tr>
    <th width="206" height="57" scope="row"><div align="left" class="style11">
      <label>
      <div align="left"><strong>Email:
        </strong>
        <input type="text" name="email" id="email" />
      </div>
      </label>
    </div></th>
    <td width="179"><div align="center"><span class="style7"><span class="style8"></span></span></div></td>
    <td width="230"><div align="center"><span class="style7"><span class="style8"></span></span></div></td>
    <td width="255"><div align="center"><span class="style7"><span class="style8"></span></span></div></td>
  </tr>
<tr>
    <th width="206" height="68" scope="row"><div align="left" class="style11">
      <label>
      <div align="left"><strong>Site:
        </strong>
        <input type="text" name="site" id="site" />
      </div>
      </label>
    </div></th>
    <td width="179"><div align="center"><span class="style7"><span class="style8"></span></span></div></td>
    <td width="230"><div align="center"><span class="style7"><span class="style8"></span></span></div></td>
    <td width="255"><div align="center"><span class="style7"><span class="style8"></span></span></div></td>
  </tr>
<tr>
    <th width="206" height="31" scope="row"><div align="center"><span class="style7"></span></div></th>
    <td width="179"><div align="center"><span class="style7"><span class="style8"></span></span></div></td>
    <td width="230"><div align="center"><span class="style7"><span class="style8"></span></span></div></td>
    <td width="255"><div align="center"><span class="style7"><span class="style8"></span></span></div></td>
  </tr>
  <tr>
    <th width="206" scope="row"><div align="left" class="style12">
      <div align="left">Standard Supplies</div>
    </div></th>
    <td width="179"><div align="center"><span class="style7"><span class="style8"></span></span></div></td>
    <td width="230"><div align="center"><span class="style7"><span class="style8"></span></span></div></td>
    <td width="255"><div align="center"><span class="style7"><span class="style8"></span></span></div></td>
  </tr>
  <tr>
    <td height="61" scope="row">
          <div align="center"><span class="style4">
          </span></div>
          <label>      </label>        
          <label>
          <div align="left" class="style11">
            <div align="center">
              <input type="checkbox" name="ratesheet[]" id="Ratesheet" value="Yes" />        
              Ratesheet</div>
        </div>
          <div align="center"><span class="style11">
          </label>
          </span>
            <label>Quantity
            <select name="ratesheetquantity[]" id="ratesheet_quantity">
              <option selected="selected">-</option>
              <option>500</option>
              <option>1000</option>
              <option>1500</option>
              <option>2000</option>
            </select>
            </label>
          </div></td>
    <td>
      <label>
      <div align="center" class="style9">
        <input type="checkbox" name="tabledrape[]" id="Tabledrape" value="Yes" />
        Table Drape</div>
      <div align="center"><span class="style9">
        </label>
        <label>Quantity
        <select name="tabledrapequantity[]" id="tabledrape_quantity">
              <option selected="selected">-</option>
              <option>500</option>
              <option>1000</option>
              <option>1500</option>
              <option>2000</option>
        </select>
        </label>
      </span></div></td>
    <td>
      <label>
      <div align="center" class="style9">
        <input type="checkbox" name="bannerstands[]" id="Banner_stands" value="Yes" />
        Banner Stands</div>
      <span class="style9">
      </label>
      <label>
      <div align="center">Quantity
        <select name="bannerstandsquantity[]" id="bannerstands_quantity">
          <option selected="selected">-</option>
          <option>500</option>
          <option>1000</option>
          <option>1500</option>
          <option>2000</option>
          </select>
      </div>
      </label>
      </span></td>
    <td>
      <label>
      <div align="center" class="style9">
        <input type="checkbox" name="tshirts[]" id="T_shirts" value="Yes" />
        Tshirts</div>
      <span class="style9">
      </label>
      <label>
      <div align="center">Quantity
        <select name="tshirtsquantity[]" id="tshirts_quantity">
          <option selected="selected">-</option>
          <option>500</option>
          <option>1000</option>
          <option>1500</option>
          <option>2000</option>
          </select>
      </div>
      </label>
      </span></td>
  </tr>
  <tr>
    <th scope="row"><div align="center"><span class="style7"></span></div></th>
    <td><div align="center"><span class="style7"><span class="style8"></span></span></div></td>
    <td><div align="center"><span class="style7"><span class="style8"></span></span></div></td>
    <td><div align="center"><span class="style7"><span class="style8"></span></span></div></td>
  </tr>
  <tr>
    <th scope="row"><div align="left" class="style12">
      <div align="left">No Worries Campaign</div>
    </div></th>
    <td><div align="center"><span class="style7"><span class="style8"></span></span></div></td>
    <td><div align="center"><span class="style7"><span class="style8"></span></span></div></td>
    <td><div align="center"><span class="style7"><span class="style8"></span></span></div></td>
  </tr>
  <tr>
    <td scope="row"><div align="left" class="style11">
      <div align="left">Flyers</div>
    </div></td>
    <td><div align="center"><span class="style7"><span class="style8"></span></span></div></td>
    <td><div align="center"><span class="style7"><span class="style8"></span></span></div></td>
    <td><div align="center"><span class="style7"><span class="style8"></span></span></div></td>
  </tr>
  <tr>
    <td scope="row">
          <div align="center"><span class="style4">
          </span></div>
        <label>      </label>        
          <label>
        <div align="left" class="style11">
            
          <div align="center">
            <input type="checkbox" name="checkbox[]" id="class" value="class_flyer" />
            Class In Ten Minutes</div>
        </div>
          <div align="center"><span class="style11">
            <label>Quantity
            <select name="quantity[]" id="Flyer_Class">
              <option>1</option>
            </select>
            </label>
          </label>
          </span></div></td>
    <td>
      <label>
      <div align="center" class="style9">
        <input type="checkbox" name="checkbox[]" id="apartment" value="apartment_flyer" />
        Apartment Hunting</div>
      <span class="style9">
      </label>
      </span></td>
    <td>
      <label>
      <div align="center" class="style9">
        <input type="checkbox" name="checkbox[]" id="roommate_flyer" value="roommate_flyer" />
        Roomate Hasn't Paid Up</div>
      <span class="style9">
      </label>
      </span></td>
    <td>
      <label>
      <div align="center" class="style9">
        <input type="checkbox" name="checkbox[]" id="olds_flyer" value="olds_flyer" />
        Olds Cramping Your Style?</div>
      <span class="style9">
      </label>
      </span></td>
  </tr>
  <tr>
    <th scope="row"><div align="center"><span class="style7"></span></div></th>
    <td><div align="center"><span class="style7"><span class="style8"></span></span></div></td>
    <td><div align="center"><span class="style7"><span class="style8"></span></span></div></td>
    <td><div align="center"><span class="style7"><span class="style8"></span></span></div></td>
  </tr>
  <tr>
    <th scope="row"><div align="left" class="style11">
      <div align="left">Posters</div>
    </div></th>
    <td><div align="center"><span class="style7"><span class="style8"></span></span></div></td>
    <td><div align="center"><span class="style7"><span class="style8"></span></span></div></td>
    <td><div align="center"><span class="style7"><span class="style8"></span></span></div></td>
  </tr>
  <tr>
    <td scope="row">
          <div align="center" class="style7">          </div>
          <div align="center"><span class="style4">
          </span></div>
      <label>      </label>        
          <label>
        <div align="left" class="style11">
            
          <div align="center">
            <input type="checkbox" name="checkbox[]" id="Class In Ten Minutes?" value="class_poster" />
            Class In Ten Minutes?</div>
        </div>
          <div align="center"><span class="style11">
          </label>
          </span></div></td>
    <td>
      <label>
      <div align="center" class="style9">
        <input type="checkbox" name="checkbox[]" id="apartment_poster" value="apartment_poster" />
        Apartment Hunting?</div>
      <span class="style9">
      </label>
      </span></td>
    <td>
      <label>
      <div align="center" class="style9">
        <input type="checkbox" name="checkbox[]" id="roommate_poster" value="roommate_poster" />
        Roommate Hasn't Paid Up?</div>
      <span class="style9">
      </label>
      </span></td>
    <td>      <label>
      <div align="center" class="style9">
        <input type="checkbox" name="checkbox[]" id="olds_poster" value="olds_poster" />
        Olds Cramping You Style?</div>
      <span class="style9">
      </label>
      </span></td>
  </tr>
  <tr>
    <th scope="row"><div align="center"><span class="style7"></span></div></th>
    <td><div align="center"><span class="style7"><span class="style8"></span></span></div></td>
    <td><div align="center"><span class="style7"><span class="style8"></span></span></div></td>
    <td><div align="center"><span class="style7"><span class="style8"></span></span></div></td>
  </tr>
  <tr>
    <th scope="row"><div align="left" class="style11">
      <div align="left">Banners</div>
    </div></th>
    <td><div align="center"><span class="style7"><span class="style8"></span></span></div></td>
    <td><div align="center"><span class="style7"><span class="style8"></span></span></div></td>
    <td><div align="center"><span class="style7"><span class="style8"></span></span></div></td>
  </tr>
  <tr>
    <td scope="row">
          <div align="center"><span class="style4">
          </span></div>
         <label>      </label>        
          <label>
        <div align="left" class="style11">
          <div align="center">
            <input type="checkbox" name="checkbox[]" id="class_banner" value="class_banner" />
            <span class="style5">Class In Ten Minutes?</span></div>
        </div>
          <div align="center"><span class="style11">
          </label>
          </span></div></td>
    <td>
      <label>
      <div align="center" class="style9">
          <input type="checkbox" name="checkbox[]" id="apartment_banner" value="apartment_banner" />
          Apartment Hunting?</div>
      <span class="style9">
      </label>
      </span></td>
    <td>
      <label>
      <div align="center" class="style9">
          <input type="checkbox" name="checkbox[]" id="roommate_banner" value="roommate_banner" />
        Roommate Hasn't Paid Up?</div>
      <span class="style9">
      </label>
      </span></td>
    <td>
      <label>
      <div align="center" class="style9">
          <input type="checkbox" name="checkbox[]" id="olds_banner" value="olds_banner[]" />
        Olds Cramping Your Style?</div>
      <span class="style9">
      </label>
      </span></td>
  </tr>
  <tr>
    <th scope="row"><div align="center"><span class="style7"></span></div></th>
    <td><div align="center"><span class="style7"><span class="style8"></span></span></div></td>
    <td><div align="center"><span class="style7"><span class="style8"></span></span></div></td>
    <td><div align="center"><span class="style7"><span class="style8"></span></span></div></td>
  </tr>
  <tr>
    <th scope="row"><div align="left" class="style11">
      <div align="left">Postcards</div>
    </div></th>
    <td><div align="center"><span class="style7"><span class="style8"></span></span></div></td>
    <td><div align="center"><span class="style7"><span class="style8"></span></span></div></td>
    <td><div align="center"><span class="style7"><span class="style8"></span></span></div></td>
  </tr>
  <tr>
    <td scope="row">
          <div align="center"><span class="style7">
          </span></div>
          <label>      </label>        
          <label>
        <div align="left" class="style11">
            
          <div align="center">
            <input type="checkbox" name="checkbox[]" id="class_postcard" value="class_postcard" />
            Class In Ten Minutes?</div>
        </div>
          <div align="center"><span class="style11">
          </label>
          </span></div></td>
    <td>
      <label>
      <div align="center" class="style9">
        <input type="checkbox" name="checkbox[]" id="apartment_postcard" value="apartment_postcard" />
        Apartment Hunting?</div>
      <span class="style9">
      </label>
      </span></td>
    <td>
      <label>
      <div align="center" class="style9">
        <input type="checkbox" name="checkbox[]" id="roommate_postcard" value="roommate_postcard" />
        Roommate Hasn't Paid Up?</div>
      <span class="style9">
      </label>
      </span></td>
    <td>
      <label>
      <div align="center" class="style9">
        <input type="checkbox" name="checkbox[]" id="olds_postcard" value="olds_postcard" />
        Olds Cramping Your Style?</div>
      <span class="style9">
      </label>
      </span></td>
  </tr>
  <tr>
    <td scope="row">
          <div align="center"><span class="style4">
          </span></div>
         <label>      </label>        
          <label>
          <div align="left" class="style11">
            
            <div align="center">
              <input type="checkbox" name="checkbox[]" id="foreign_postcard" value="foreign_postcard" />
              Foreign City?</div>
        </div>
          <div align="center"><span class="style11">
          </label>
          </span></div></td>
    <td><div align="center"><span class="style7"><span class="style8"></span></span></div></td>
    <td><div align="center"><span class="style7"><span class="style8"></span></span></div></td>
    <td><div align="center"><span class="style7"><span class="style8"></span></span></div></td>
  </tr>
  <tr>
    <th scope="row"><div align="center"><span class="style7"></span></div></th>
    <td>
        <div align="center" class="style9">
          <input type="submit" name="submit" id="submit" value="Submit" />    
      </div></td>
    <td><div align="center"><span class="style7"><span class="style8"></span></span></div></td>
    <td><div align="center"><span class="style7"><span class="style8"></span></span></div></td>
  </tr>
</table>
 
<p>&nbsp;</p>
</form>
</body>
</html>

Open in new window

0
 

Author Comment

by:natsully
ID: 22670571
this is the php
<style type="text/css">
<!--
body {
	background-color: #999999;
}
-->
</style><?php
 
function isEmail($email) {
        return (preg_match('/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i', $email))? true : false;
}
 
$name = $_POST['name'];
$email = (isEmail($_POST['email']))? $_POST['email'] : "";
$site = $_POST['site'];
$ratesheet = $_POST['ratesheet'];
$ratesheetquantity = $_POST['ratesheetquantity'];
$tabledrape = $_POST['tabledrape'];
$tabledrapequantity = $_POST['tabledrapequantity'];
$bannerstands = $_POST['bannerstands'];
$bannerstandsquantity = $_POST['bannerstandsquantity'];
$tshirts = $_POST['tshirts'];
$tshirtsquantity = $_POST['tshirtsquantity'];
$checkbox = $_POST['checkbox'];
$quantity = $_POST['quantity'];
$string = $_SERVER['QUERY_STRING'];
 
if ($name == "") die ("Please enter your name."); 
if ($email == "") die ("Please enter a valid email.");
if ($site == "") die ("Please enter your site.");
 
 
?>
<?php
if (!$email) {
?>
<?php
}
else {
if ($email) {
 
    $name = $_POST['name'];
    $email = $_POST['email'];
	$site = $_POST['site'];
	$ratesheet = implode (", ", $_POST['ratesheet']);
	$ratesheetquantity = implode (", ", $_POST['ratesheetquantity']);
	$tabledrape = implode (", ", $_POST['tabledrape']);
	$tabledrapequantity = implode (", ", $_POST['tabledrapequantity']);
	$bannerstands = $_POST['bannerstands'];
	$bannerstandsquantity = $_POST['bannerstandsquantity'];
	$tshirts = implode (", ", $_POST['tshirts']);
	$tshirtsquantity = implode (", ", $_POST['tshirtsquantity']);
	$checkbox = implode(", ", $_POST['checkbox']);
	$quantity = implode(", ", $_POST['quantity']);
 
   
     // change this to whatever you needed to be.
    $recipient = 'myemail@email.com';
 
    //you can make it say anything you want
    $subject = 'Directors Order Form';
 
 
	$headers = "From: DirectorsForm\n" .
    "Reply-To: $Email\n" .
    'Content-type: text/html; charset=iso-8859-1' . "\n" .
 
    $content = "<html><head><title>Directors Order Form</title></head><body><br />";
    $content .= "name: <b>" . $name . "</b><br />";
    $content .= "email: <b>" . $email . "</b><br />";
	$content .= "site: <b>" . $site . "</b><br>";
    $content .= "Options: <b>" . $checkbox . "</b><br />";
	$content .= "Quantity: <b>" . $quantity . "</b><br /><hr />";
	$content .= "Ratesheet: <b>" . $ratesheet . " " . $ratesheetquantity . "</b><br />";
	$content .= "Table Drape: <b>" . $tabledrape . " " . $tabledrapequantity . "</b><br />";
	$content .= "Banner Stands: <b>" . $bannerstands . " " . $bannerstandsquantity . "</b><br />";
	$content .= "Tshirt: <b>" . $tshirts . " " . $tshirtsquantity . "</b><br />";
    $content .= "<br /></body>";
   
 
    // The mail() function allows you to send mail.
    mail($recipient,$subject,$content,$headers);
 
                    
  }
 
 
echo "<center><br><br><font face=Arial size=3 color=black>Thank you <font color=white>$name</font>. Your choice has been submitted. <p>";
}
?>

Open in new window

0
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

 

Author Comment

by:natsully
ID: 22670580
I've only started the check boxes and quantity on the first row of products.

with the "implode" function it gives an error on the "thanks" page if the items wasn't checked
0
 
LVL 82

Expert Comment

by:hielo
ID: 22671090
what you need to do is give all your "Standard Supplies" checkboxes the same name, but give each a unique value:
<input type="StandardSupplies[]" value="Ratesheet"/>
<input type="StandardSupplies[]" value="Table_Drape"/>
<input type="StandardSupplies[]" value="Banner_Stands"/>
<input type="StandardSupplies[]" value="T_Shirts"/>
 
With that markup, on the php you can then determine the checked items using this:
 
 
Now, to get the corresponding quantity, you can use this:
<select name="#VALUEOFCHECKBOX#_quantity">
              <option selected="selected" value="0">-</option>
              <option>500</option>
              <option>1000</option>
              <option>1500</option>
              <option>2000</option>
            </select>
 
where #VALUEOFCHECKBOX# equals the value of the corresponding checkbox-ex:
<select name="Ratesheet_quantity">...</select>
<select name="Table_Drape_quantity">...</select>
<select name="Banner_Stands_quantity">...</select>
<select name="T_Shirts_quantity">...</select>
 
 
Thus, to get the corresponding quantity you would use:
foreach($_POST['StandardSupplies'] as $value)
{
  //at this point, $value contains the value of the checked item
  //use that to read the corresponding quantity
  $key=$value . "_quantity";
 echo "Selected " . $_POST[$key] . " $value";
}

Open in new window

0
 
LVL 82

Expert Comment

by:hielo
ID: 22671463
this should be very close to what you are trying to do:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">
 
<html>
<head>
<title></title>
<style type="text/css">
<!--
.row1{float:left;width:25%;}
.col1{float:left;width:49%;}
fieldset{padding:5px;}
fieldset div select{display:block;}
legend{font-weight:bold;background-color:white;}
fieldset fieldset{border:0px; border-top:1px dashed black;margin-top:1em;}
-->
</style>
 
</head>
<body>
<form id="form1" name="form1" method="post" action="orderform_thanks.php">
	<fieldset><legend>Standard Supplies</legend>
		<div class="row1"><input type="checkbox" name="StandardSupplies[]" value="RateSheet" />Ratesheet <select name="RateSheet_quantity"><option value="0">-</option><option value="500">500</option><option value="1000">1000</option><option value="1500">1500</option><option value="2000">2000</option></select></div>
		<div class="row1"><input type="checkbox" name="StandardSupplies[]" value="Table_Drape" />Table Drape <select name="Table_Drape_quantity"><option value="0">-</option><option value="500">500</option><option value="1000">1000</option><option value="1500">1500</option><option value="2000">2000</option></select></div>
		<div class="row1"><input type="checkbox" name="StandardSupplies[]" value="Banner_Stands" />Banner Stands <select name="Banner_Stands_quantity"><option value="0">-</option><option value="500">500</option><option value="1000">1000</option><option value="1500">1500</option><option value="2000">2000</option></select></div>
		<div><input type="checkbox" name="StandardSupplies[]" value="T_Shirts" />T-Shirts <select name="T_Shirts_quantity"><option value="0">-</option><option value="500">500</option><option value="1000">1000</option><option value="1500">1500</option><option value="2000">2000</option></select></div>
	</fieldset>
 
	<fieldset><legend>No Worries Campaign</legend>
		<div>Quantity: <input type="text" name="NWC_quantity"/></div>
		<fieldset><legend>Flyers</legend>
			<div class="col1"><input type="checkbox" name="Flyers[]" value="Class In Ten Minutes?"/>Class In Ten Minutes?</div>
			<div><input type="checkbox" name="Flyers[]" value="Apartment Hunting?"/>Apartment Hunting?</div>
			<div class="col1"><input type="checkbox" name="Flyers[]" value="Roommate hasn't paid up?"/>Roommate hasn't paid up?</div>
			<div><input type="checkbox" name="Flyers[]" value="Olds Cramping Your Style?"/>Olds Cramping Your Style?</div>
		</fieldset>
 
		<fieldset><legend>Posters</legend>
			<div class="col1"><input type="checkbox" name="Posters[]" value="Class In Ten Minutes?"/>Class In Ten Minutes?</div>
			<div><input type="checkbox" name="Posters[]" value="Apartment Hunting?"/>Apartment Hunting?</div>
			<div class="col1"><input type="checkbox" name="Posters[]" value="Roommate hasn't paid up?"/>Roommate hasn't paid up?</div>
			<div><input type="checkbox" name="Posters[]" value="Olds Cramping Your Style?"/>Olds Cramping Your Style?</div>
		</fieldset>
 
		<fieldset><legend>Banners</legend>
			<div class="col1"><input type="checkbox" name="Banners[]" value="Class In Ten Minutes?"/>Class In Ten Minutes?</div>
			<div><input type="checkbox" name="Banners[]" value="Apartment Hunting?"/>Apartment Hunting?</div>
			<div class="col1"><input type="checkbox" name="Banners[]" value="Roommate hasn't paid up?"/>Roommate hasn't paid up?</div>
			<div><input type="checkbox" name="Banners[]" value="Olds Cramping Your Style?"/>Olds Cramping Your Style?</div>
		</fieldset>
 
		<fieldset><legend>Post Cards</legend>
			<div class="col1"><input type="checkbox" name="Post_Cards[]" value="Class In Ten Minutes?"/>Class In Ten Minutes?</div>
			<div><input type="checkbox" name="Post_Cards[]" value="Apartment Hunting?"/>Apartment Hunting?</div>
			<div class="col1"><input type="checkbox" name="Post_Cards[]" value="Roommate hasn't paid up?"/>Roommate hasn't paid up?</div>
			<div><input type="checkbox" name="Post_Cards[]" value="Olds Cramping Your Style?"/>Olds Cramping Your Style?</div>
		</fieldset>
	</fieldset>
	
</form>
</body>
</html>
 
orderform_thanks.php
<?php
$submittedData="";
foreach($_POST['StandardSupplies'] as $value)
{
	$k=$value."_quantity";
	$submittedData .= "\n".str_replace("_"," ",$value) . ": " . $_POST[$k];
}
$submittedData .="\nNo Worries Campaign";
$submittedData .="\nQuantity: " . $_POST['NWC_quantity'];
$nwc=array('Flyers','Posters','Banners','Post_Cards');
foreach($nwc as $chk)
{
	$submittedData .= "\n" . $chk;
	foreach($_POST[$chk] as $value)
	{
		$submittedData .= "\n\t".str_replace("_"," ",$value);
	}
}
if(!empty(!submittedData))
{
	mail("you@yourcompany.com","Order details",$submittedData);
	echo "Thank you!";
}
?>

Open in new window

0
 

Author Comment

by:natsully
ID: 22671851
It says "Warning: Invalid argument supplied for foreach() in /usr/local/plesk/apache/vhosts/campushousing.com/httpdocs/orderform/orderform_thanks.php on line 14

Warning: Invalid argument supplied for foreach() in /usr/local/plesk/apache/vhosts/campushousing.com/httpdocs/orderform/orderform_thanks.php on line 14

Warning: Invalid argument supplied for foreach() in /usr/local/plesk/apache/vhosts/campushousing.com/httpdocs/orderform/orderform_thanks.php on line 14

Warning: Invalid argument supplied for foreach() in /usr/local/plesk/apache/vhosts/campushousing.com/httpdocs/orderform/orderform_thanks.php on line 14
Thank you!"

Line 14 is
      foreach($_POST[$chk] as $value)
0
 

Author Comment

by:natsully
ID: 22671959
i really need to have all the items structured like the first line too. (checkbox, quantity) because they need to have the option to (for example) order 500 Class Flyers and 1500 apartment postcards.
0
 

Author Comment

by:natsully
ID: 22672018
I also have to have the required name, email, and site.
0
 
LVL 82

Accepted Solution

by:
hielo earned 2000 total points
ID: 22672109
save this as natsully.php (it's just ONE file, not two) and provide a valid email address, then try it.
<?php
if( !empty($_POST['action']) )
{
	header("Content-type: text/plain");
	$submittedData="";
	foreach($_POST['StandardSupplies'] as $value)
	{
		$k=$value."_quantity";
		if(!empty($_POST[$k]))
			$submittedData .= "\n".str_replace("_"," ",$value) . ": " . $_POST[$k];
	}
	$submittedData .="\nNo Worries Campaign";
	$submittedData .="\n\tQuantity: " . $_POST['NWC_quantity'];
	$nwc=array('Flyers','Posters','Banners','Post_Cards');
	foreach($nwc as $chk)
	{
		if( !empty($_POST[$chk]) )
		{
			$submittedData .= "\n\t" . $chk.":";
			foreach($_POST[$chk] as $value)
			{
				$submittedData .= "\n\t\t".str_replace("_"," ",$value);
			}
		}
	}
	if(!empty($submittedData))
	{
		mail("you@yourcompany.com","Order details",$submittedData);
		echo "\n\nThank you!";
	}
	exit;
}
?>
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">
 
<html>
<head>
<title></title>
<style type="text/css">
<!--
.row1{float:left;width:25%;}
.col1{float:left;width:49%;}
fieldset{padding:5px;}
fieldset div select{display:block;}
legend{font-weight:bold;background-color:white;}
fieldset fieldset{border:0px; border-top:1px dashed black;margin-top:1em;}
-->
</style>
 
</head>
<body>
<form id="form1" name="form1" method="post" action="<?=$_SERVER['PHP_SELF']?>">
	<fieldset><legend>Standard Supplies</legend>
		<div class="row1"><input type="checkbox" name="StandardSupplies[]" value="RateSheet" />Ratesheet <select name="RateSheet_quantity"><option value="0">-</option><option value="500">500</option><option value="1000">1000</option><option value="1500">1500</option><option value="2000">2000</option></select></div>
		<div class="row1"><input type="checkbox" name="StandardSupplies[]" value="Table_Drape" />Table Drape <select name="Table_Drape_quantity"><option value="0">-</option><option value="500">500</option><option value="1000">1000</option><option value="1500">1500</option><option value="2000">2000</option></select></div>
		<div class="row1"><input type="checkbox" name="StandardSupplies[]" value="Banner_Stands" />Banner Stands <select name="Banner_Stands_quantity"><option value="0">-</option><option value="500">500</option><option value="1000">1000</option><option value="1500">1500</option><option value="2000">2000</option></select></div>
		<div><input type="checkbox" name="StandardSupplies[]" value="T_Shirts" />T-Shirts <select name="T_Shirts_quantity"><option value="0">-</option><option value="500">500</option><option value="1000">1000</option><option value="1500">1500</option><option value="2000">2000</option></select></div>
	</fieldset>
 
	<fieldset><legend>No Worries Campaign</legend>
		<div>Quantity: <input type="text" name="NWC_quantity"/></div>
		<fieldset><legend>Flyers</legend>
			<div class="col1"><input type="checkbox" name="Flyers[]" value="Class In Ten Minutes?"/>Class In Ten Minutes?</div>
			<div><input type="checkbox" name="Flyers[]" value="Apartment Hunting?"/>Apartment Hunting?</div>
			<div class="col1"><input type="checkbox" name="Flyers[]" value="Roommate hasn't paid up?"/>Roommate hasn't paid up?</div>
			<div><input type="checkbox" name="Flyers[]" value="Olds Cramping Your Style?"/>Olds Cramping Your Style?</div>
		</fieldset>
 
		<fieldset><legend>Posters</legend>
			<div class="col1"><input type="checkbox" name="Posters[]" value="Class In Ten Minutes?"/>Class In Ten Minutes?</div>
			<div><input type="checkbox" name="Posters[]" value="Apartment Hunting?"/>Apartment Hunting?</div>
			<div class="col1"><input type="checkbox" name="Posters[]" value="Roommate hasn't paid up?"/>Roommate hasn't paid up?</div>
			<div><input type="checkbox" name="Posters[]" value="Olds Cramping Your Style?"/>Olds Cramping Your Style?</div>
		</fieldset>
 
		<fieldset><legend>Banners</legend>
			<div class="col1"><input type="checkbox" name="Banners[]" value="Class In Ten Minutes?"/>Class In Ten Minutes?</div>
			<div><input type="checkbox" name="Banners[]" value="Apartment Hunting?"/>Apartment Hunting?</div>
			<div class="col1"><input type="checkbox" name="Banners[]" value="Roommate hasn't paid up?"/>Roommate hasn't paid up?</div>
			<div><input type="checkbox" name="Banners[]" value="Olds Cramping Your Style?"/>Olds Cramping Your Style?</div>
		</fieldset>
 
		<fieldset><legend>Post Cards</legend>
			<div class="col1"><input type="checkbox" name="Post_Cards[]" value="Class In Ten Minutes?"/>Class In Ten Minutes?</div>
			<div><input type="checkbox" name="Post_Cards[]" value="Apartment Hunting?"/>Apartment Hunting?</div>
			<div class="col1"><input type="checkbox" name="Post_Cards[]" value="Roommate hasn't paid up?"/>Roommate hasn't paid up?</div>
			<div><input type="checkbox" name="Post_Cards[]" value="Olds Cramping Your Style?"/>Olds Cramping Your Style?</div>
		</fieldset>
	</fieldset>
	<div><input type="submit" name="action" value="Submit"/></div>
</form>
</body>
</html>

Open in new window

0
 

Author Comment

by:natsully
ID: 22672213
Definitely getting closer! No errors.
Now if we could just add a Name, Email, Site inputs that are submitted in the email as well.
Is there any way to make the users email the "From" email.

And to add individual quantities to the "No Worries" Products.

Also (I know I have a lot of questions... sorry), how difficult would it be to add a dropdown menu that lists say 5 people that the user has to select who their Regional Manager is. So that they choose their RM and it sends a copy of the email submission to not only me but the RM they chose as well?
0
 
LVL 82

Expert Comment

by:hielo
ID: 22672374
As a premium service member, you have unlimited points to give. As per the EE rules, you should be asking only one question per post. I suggest you take the "sample" form I gave you earlier and format the form in whatever way you need it with however many other fields you have. If you then need further help processing the data, then post another problem and I'll be glad to help you.
0
 

Author Comment

by:natsully
ID: 22672436
You're right.
Sorry about that!!
Will do.
0
 

Author Closing Comment

by:natsully
ID: 31504292
Thanks
0
 
LVL 82

Expert Comment

by:hielo
ID: 22672701
No problem. Glad to help.
0

Featured Post

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question