我正在尝试检查已检查的值以便在电子邮件中过来,但它们是空白的。我正在使用引导验证代码。
我试图使用其中的每一个而没有运气:
$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[]'];
这是我的HTML:
<div class="form-group">
<label><h4>WHAT ACCOUNTING SERVICES/FUNCTIONS ARE NEEDED?</h4>Mark as many as necessary)</label>
<div class="checkbox">
<label><input type="checkbox" name="accounting_services[]" value="Accounts Payable - Entering bills"/>Accounts Payable - Entering bills</label>
</div>
<div class="checkbox">
<label><input type="checkbox" name="Accounting_Services[]" value="Accounts Payable – Paying Bills w/ Approval"/>Accounts Payable – Paying Bills w/ Approval</label>
</div>
<div class="checkbox">
<label><input type="checkbox" name="Accounting_Services[]" value="Accounts Receivable – Invoicing clients"/>Accounts Receivable – Invoicing clients</label>
</div>
<div class="checkbox">
<label><input type="checkbox" name="Accounting_Services[]" value="Accounts Receivable – Entering receive payments and deposits"/>Accounts Receivable – Entering receive payments and deposits</label>
</div>
</div>
这是PHP代码:
<?php
// check if fields passed are empty
if(empty($_POST['name']) ||
empty($_POST['businessname']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!";
return false;
}
if(isset($_POST['submit'])){//to run PHP script on submit
if(!empty($_POST['accounting_services'])){
foreach($_POST['accounting_services'] as $accountingselected){
echo $accountingselected."</br>";
}
}
}
$name = $_POST['name'];
$businessname = $_POST['businessname'];
$to = 'email@email.com';
$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";
mail($to,$email_subject,$email_body,$headers);
return true;
?>
答案 0 :(得分:0)
更改您的代码如下。
$accounting_services = isset($_POST['accounting_services']) ?$_POST['accounting_services'] : "";