How to add "if" to implode PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nabelou
Forum Newbie
Posts: 1
Joined: Mon Feb 24, 2014 4:01 pm

How to add "if" to implode PHP

Post by nabelou »

I have contact form using PHP and implode, when I submit the form and a checkbox is not checked it gives error line, i want to know if there is a way to only use implode if the checkbox is checked.

Code: Select all

<?php
$email_message .= "Logo: ".implode(" ", $_POST['package'])."\n";
$email_message .= "Type: ".implode(" ", $_POST['package2'])."\n";
$email_message .= "Pages: ".implode(" ", $_POST['package3'])."\n";
$email_message .= "Slideshow: ".implode(" ", $_POST['package4'])."\n";
$email_message .= "Content: ".implode(" ", $_POST['package5'])."\n";
$email_message .= "Music: ".implode(" ", $_POST['package6'])."\n";
$email_message .= "Quote: ".implode(" ", $_POST['package7'])."\n";
$email_message .= "Flash: ".implode(" ", $_POST['package8'])."\n";
?>
Thank you
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: How to add "if" to implode PHP

Post by requinix »

Use isset or empty, and you should use them for not just checkboxes but every field - just to be sure.
Post Reply