Hey guys, I have a question. I've made a simple little HTML form that basically takes order form data, and e-mails the result to someone. It POSTs through a php mailer.
I know this is SO simple, but I haven't coded in PHP for literally 10 years, and so I'm rusty. I need to take the input fields from the HTML form, and have my PHP script decide if they're NULL and if they are, just go to the next. If they have something in them, they need to display in the e-mail being sent. Here's what I have that displays EVERYTHING:
<?php
if(isset($_POST['submit'])) {
$to = "submitted@emailaddress.com";
$subject = "Catalog Order Submission";
$camp1_field = $_POST['camp1'];
$page1_field = $_POST['page1'];
$sku1_field = $_POST['sku1'];
$qty1_field = $_POST['qty1'];
$camp2_field = $_POST['camp2'];
$page2_field = $_POST['page2'];
$sku2_field = $_POST['sku2'];
$qty2_field = $_POST['qty2'];
$camp3_field = $_POST['camp3'];
$page3_field = $_POST['page3'];
$sku3_field = $_POST['sku3'];
$qty3_field = $_POST['qty3'];
$camp4_field = $_POST['camp4'];
$page4_field = $_POST['page4'];
$sku4_field = $_POST['sku4'];
$qty4_field = $_POST['qty4'];
$camp5_field = $_POST['camp5'];
$page5_field = $_POST['page5'];
$sku5_field = $_POST['sku5'];
$qty5_field = $_POST['qty5'];
$camp6_field = $_POST['camp6'];
$page6_field = $_POST['page6'];
$sku6_field = $_POST['sku6'];
$qty6_field = $_POST['qty6'];
$camp7_field = $_POST['camp7'];
$page7_field = $_POST['page7'];
$sku7_field = $_POST['sku7'];
$qty7_field = $_POST['qty7'];
$camp8_field = $_POST['camp8'];
$page8_field = $_POST['page8'];
$sku8_field = $_POST['sku8'];
$qty8_field = $_POST['qty8'];
$camp9_field = $_POST['camp9'];
$page9_field = $_POST['page9'];
$sku9_field = $_POST['sku9'];
$qty9_field = $_POST['qty9'];
$camp10_field = $_POST['camp10'];
$page10_field = $_POST['page10'];
$sku10_field = $_POST['sku10'];
$qty10_field = $_POST['qty10'];
$camp11_field = $_POST['camp11'];
$page11_field = $_POST['page11'];
$sku11_field = $_POST['sku11'];
$qty11_field = $_POST['qty11'];
$camp12_field = $_POST['camp12'];
$page12_field = $_POST['page12'];
$sku12_field = $_POST['sku12'];
$qty12_field = $_POST['qty12'];
$camp13_field = $_POST['camp13'];
$page13_field = $_POST['page13'];
$sku13_field = $_POST['sku13'];
$qty13_field = $_POST['qty13'];
$camp14_field = $_POST['camp14'];
$page14_field = $_POST['page14'];
$sku14_field = $_POST['sku14'];
$qty14_field = $_POST['qty14'];
$camp15_field = $_POST['camp15'];
$page15_field = $_POST['page15'];
$sku15_field = $_POST['sku15'];
$qty15_field = $_POST['qty15'];
$camp16_field = $_POST['camp16'];
$page16_field = $_POST['page16'];
$sku16_field = $_POST['sku16'];
$qty16_field = $_POST['qty16'];
$camp17_field = $_POST['camp17'];
$page17_field = $_POST['page17'];
$sku17_field = $_POST['sku17'];
$qty17_field = $_POST['qty17'];
$camp18_field = $_POST['camp18'];
$page18_field = $_POST['page18'];
$sku18_field = $_POST['sku18'];
$qty18_field = $_POST['qty18'];
$camp19_field = $_POST['camp19'];
$page19_field = $_POST['page19'];
$sku19_field = $_POST['sku19'];
$qty19_field = $_POST['qty19'];
$camp20_field = $_POST['camp20'];
$page20_field = $_POST['page20'];
$sku20_field = $_POST['sku20'];
$qty20_field = $_POST['qty20'];
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$notes = $_POST['notes'];
$headers = "From: EMAILORDER\r\n";
$body = "Customer Name:\t$name_field\n" .
"Customer E-Mail:\t$email_field\n\n" .
"Order:\n" .
"C$camp1\t Pg.$page1\t $sku1\t $qty1 units\n" .
"C$camp2\t Pg.$page2\t $sku2\t $qty2 units\n" .
"C$camp3\t Pg.$page3\t $sku3\t $qty3 units\n" .
"C$camp4\t Pg.$page4\t $sku4\t $qty4 units\n" .
"C$camp5\t Pg.$page5\t $sku5\t $qty5 units\n" .
"C$camp6\t Pg.$page6\t $sku6\t $qty6 units\n" .
"C$camp7\t Pg.$page7\t $sku7\t $qty7 units\n" .
"C$camp8\t Pg.$page8\t $sku8\t $qty8 units\n" .
"C$camp9\t Pg.$page9\t $sku9\t $qty9 units\n" .
"C$camp10\t Pg.$page10\t $sku10\t $qty10 units\n" .
"C$camp11\t Pg.$page11\t $sku11\t $qty11 units\n" .
"C$camp12\t Pg.$page12\t $sku12\t $qty12 units\n" .
"C$camp13\t Pg.$page13\t $sku13\t $qty13 units\n" .
"C$camp14\t Pg.$page14\t $sku14\t $qty14 units\n" .
"C$camp15\t Pg.$page15\t $sku15\t $qty15 units\n" .
"C$camp16\t Pg.$page16\t $sku16\t $qty16 units\n" .
"C$camp17\t Pg.$page17\t $sku17\t $qty17 units\n" .
"C$camp18\t Pg.$page18\t $sku18\t $qty18 units\n" .
"C$camp19\t Pg.$page19\t $sku19\t $qty19 units\n" .
"C$camp20\t Pg.$page20\t $sku20\t $qty20 units\n\n" .
"Order Notes:\n$notes";
echo "Thanks for your order, I will send you a confirmation as soon as I receive it!";
mail($to, $subject, $body, $headers);
} else {
echo "ERROR";
}
?>
So, as you can see - it's a simple form, but has 80+ variables, because on the form, there's a total of 20 "order lines". You get the idea from the variables here - on the form, it asks for a "camp" number, the page number, the sku number and the qty. But, most people will have maybe 5 items they need - in that case, the output e-mail doesn't need to have the excess 15 lines.
I've tried to screw around with isset() and empty(), but I can't figure out how to wing it. Do I basically need an if isset statement for each variable? What's my best practice here?
Thanks guys!