html - Checkbox Value in form coming over blank PHP


I am trying to check the checked values to come over in email but they are coming over blank. I am using the bootstrap validation code.

I tried to use each of these as well with no luck:

$accounting_services = !empty($_POST['accounting_services[]']) ? array() : $_POST['accounting_services[]']; 

$accounting_services = !empty($_POST['accounting_services[]']) ? implode(' | ', $_POST['accounting_services[]']) 

$accounting_services = nl2br(implode(',',$_POST['accounting_services[]'];

Here is my HTML:

  <div >
     <label><h4>WHAT ACCOUNTING SERVICES/FUNCTIONS ARE NEEDED?</h4>Mark as many as necessary)</label>
     <div >
      <label><input type="checkbox" name="accounting_services[]" value="Accounts Payable - Entering bills"/>Accounts Payable - Entering bills</label>
     <div >
      <label><input type="checkbox" name="Accounting_Services[]" value="Accounts Payable – Paying Bills w/ Approval"/>Accounts Payable – Paying Bills w/ Approval</label>
     <div >
      <label><input type="checkbox" name="Accounting_Services[]" value="Accounts Receivable – Invoicing clients"/>Accounts Receivable – Invoicing clients</label>
     <div >
      <label><input type="checkbox" name="Accounting_Services[]" value="Accounts Receivable – Entering receive payments and deposits"/>Accounts Receivable – Entering receive payments and deposits</label>

Here is the PHP code:

// check if fields passed are empty
if(empty($_POST['name'])        ||
   empty($_POST['businessname']) ||

    echo "No arguments Provided!";
    return false;
    if(isset($_POST['submit'])){//to run PHP script on submit
foreach($_POST['accounting_services'] as $accountingselected){
echo $accountingselected."</br>";
$name = $_POST['name'];
$businessname = $_POST['businessname'];

$to = '[email protected]'; 
$email_subject = "Contact form submitted by:  $name from $businessname";
$email_body = "You have received a new message. \n\n".
                  " Here are the details:\n \n ".
                  "Name: $name \n ".
                  "Business Name: $businessname \n ".
                  "Accounting Services: $accountingselected \n".;
$headers = "From: $email_address\n";
$headers .= "Reply-To: $email_address"; 
return true;            



Change your code as follow.

$accounting_services = isset($_POST['accounting_services']) ?$_POST['accounting_services'] : ""; 

People are also looking for solutions to the problem: how to convert p tag to line break in php fpdf


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.