2017-06-08 16 views
0

複数のチェックボックスがあるフォームがありますが、選択したすべてのリストを取得できません。ここ は、部分的に私の形である:ここでは入力チェックボックスのリストを取得できません

<form action="error" id="contact" method="post" name="contact"> 
<div class="form-step animated" id="form-step-1" style="display: block;"> 
    <h1>What are you or your loved one struggling with?</h1> 
    <div class="info"> 
     <span class="txt">Check all that apply</span> 
    </div> 
    <ul class="services-list clearfix"> 
     <li> 
      <div class="service"> 
       <label class="checkbox"><input name="problem" type="checkbox" value="Alcoholism"> <span class="icon"><i class="check"></i></span> <span class="label">Alcoholism</span></label> 
      </div> 
     </li> 
     <li> 
      <div class="service"> 
       <label class="checkbox"><input name="problem" type="checkbox" value="Drug Abuse"> <span class="icon"><i class="check"></i></span> <span class="label">Drug Abuse</span></label> 
      </div> 
     </li> 
     <li> 
      <div class="service"> 
       <label class="checkbox"><input name="problem" type="checkbox" value="Opiates"> <span class="icon"><i class="check"></i></span> <span class="label">Opiates</span></label> 
      </div> 
     </li> 
     <li> 
      <div class="service"> 
       <label class="checkbox"><input name="problem" type="checkbox" value="Eating Disorder"> <span class="icon"><i class="check"></i></span> <span class="label">Eating Disorder</span></label> 
      </div> 
     </li> 
     <li> 
      <div class="service"> 
       <label class="checkbox"><input name="problem" type="checkbox" value="Gambling"> <span class="icon"><i class="check"></i></span> <span class="label">Gambling</span></label> 
      </div> 
     </li> 
     <li> 
      <div class="service"> 
       <label class="checkbox"><input name="problem" type="checkbox" value="Mental Health"> <span class="icon"><i class="check"></i></span> <span class="label">Mental Health</span></label> 
      </div> 
     </li> 
    </ul> 
</div> 
<input id="realSubmit" type="submit"> 

は、フォームハンドラのためのPHPコードです:

<?php 
$errors = ''; 
$myemail = '[email protected]';//<-----Put Your email address here. 
if(empty($_POST['problem']) || 
    empty($_POST['patient_name']) || 
    empty($_POST['patient_phone']) || 
    empty($_POST['patient_birth']) || 
    empty($_POST['patient_address']) || 
    empty($_POST['insurance']) || 
    empty($_POST['ins_digits']) || 
    empty($_POST['ins_provider']) || 
    empty($_POST['ins_provider_phone']) || 
    empty($_POST['group_id']) || 
    empty($_POST['member_id'])) { 
    $errors .= "\n Error: All fields are required"; 
} 
// $problem = $_POST['problem']; 
$problems = implode("," , $_POST['problem']); 
$patient_name = $_POST['patient_name']; 
$patient_phone = $_POST['patient_phone']; 
$patient_birth = $_POST['patient_birth']; 
$patient_address = $_POST['patient_address']; 
$insurance = $_POST['insurance']; 
$policy_holder_name = $_POST['policy_holder_name']; 
$policy_holder_phone = $_POST['policy_holder_phone']; 
$policy_holder_birth = $_POST['policy_holder_birth']; 
$policy_holder_address = $_POST['policy_holder_address']; 
$ins_digits = $_POST['ins_digits']; 
$ins_provider = $_POST['ins_provider']; 
$ins_provider_phone = $_POST['ins_provider_phone']; 
$group_id = $_POST['group_id']; 
$member_id = $_POST['member_id']; 

if (!preg_match("/^[1-9][0-9]{0,15}$/", $patient_phone)) { 
    $errors_patient_phone .= "\n Error: Invalid Phone Number of Patient"; 
} 

if (!preg_match("/^[1-9][0-9]{0,15}$/", $policy_holder_phone)) { 
    $errors_policy_holder_phone .= "\n Error: Invalid Phone Number of Policy Holder"; 
} 

if (!preg_match("/^[1-9][0-9]{0,4}$/", $ins_digits)) { 
    $errors_ins_digit .= "\n Error: Invalid Social Security Number"; 
} 
if (!preg_match("/^[1-9][0-9]{0,15}$/", $ins_provider_phone)) { 
    $errors_ins_provider_phone .= "\n Error: Invalid Phone Number of Insurance Provider"; 
} 

if(empty($errors_patient_phone) && empty($errors_patient_phone) && empty($errors_ins_digit) && empty($errors_ins_provider_phone)) { 
    $to = $myemail; 
    $email_subject = "Contact form submission from: $patient_name"; 
    $email_body = "You have received a new submission. ". 
    "Here are the details:\n Patient's Name: $patient_name \n Patient's Phone: $patient_phone \n Patient's Address: $patient_address \n Patient's Problems: $problems \n Insurance: $insurance \n Policy Holder's Name: $policy_holder_name \n Policy Holder's Phone: $policy_holder_phone \n Policy Holder's Address: $policy_holder_address \n Policy Holder's Social Security Number: $ins_digits \n Insurance Provider: $ins_provider \n Insurance Provider's Phone: $ins_provider_phone \n Group ID# $group_id \n Membar ID# $member_id"; 

    $headers[] = 'Content-Type: text/plain; charset=UTF-8'; 
    // $headers .= "Reply-To: $email_address"; 

    mail($to,$email_subject,$email_body,$headers); 
    //redirect to the 'thank you' page 
    header('Location: thank-you'); 
} 
?> 

私が選択したチェックボックスのリストを取得することはできません。

選択された入力から配列を取得できないことがあります。 提案がありますか?

+1

'名=「問題は[]」' –

+0

それを解決します。 – Mizan

答えて

3

変更problemからproblem[]にチェックボックスの名前、そしてあなたの$_POST['problem']あなたのチェックボックスの値の配列になります。

<input name="problem[]" type="checkbox" value="Gambling"> 
関連する問題