php - Not getting values from an array of checkboxes -


in form i'm building i'm having issue getting array list in email received site owner upon submission of form. here how received email looks:

company: company name
first name: bob
last name: jones
e-mail: email@gmail.com
phone: 123-652-9658
street address: 123 main street
city: albany
state: ny
zip: 12345
areas of interest:
number of windows / doors: 6
how did hear our company? google bing
additional information: hi

here form code:

<form method="post" action="sendeform.php">          <p><label for="company">company:</label> <input type="text" class="form-control" name="company" id="company" tabindex="1" /></p>         <p><label for="firstname">first name:*</label> <input type="text" class="form-control" name="firstname" id="firstname" tabindex="2" /></p>         <p><label for="lastname">last name:*</label> <input type="text" class="form-control" name="lastname" id="lastname" tabindex="3" /></p>         <p><label for="email">email:*</label> <input type="text" class="form-control" name="email" id="email" tabindex="4"  /></p>         <p><label for="phone">phone:*</label> <input type="text" class="form-control" name="phone" id="phone" tabindex="5" /></p>         <p><label for="street">street address:*</label> <input type="text" class="form-control" name="street" id="street" tabindex="6" /></p>         <p><label for="city">city:*</label> <input type="text" class="form-control" name="city" id="city" tabindex="6" /></p>         <p><label for="state">state:*</label> <input type="text" class="form-control" name="state" id="state" tabindex="6" /></p>         <p><label for="zip">zip:*</label> <input type="text" class="form-control" name="zip" id="zip" tabindex="6"  /></p>         <p><label for="interest">areas of interest:*</label><br>            <input type="checkbox" name="check_list[]" value="heat reduction" /> heat reduction<br>             <input type="checkbox" name="check_list[]" value="uv/fading" /> uv/fading<br>             <input type="checkbox" name="check_list[]" value="wall finishes" /> wall finishes<br>             <input type="checkbox" name="check_list[]" value="sun control" /> sun control<br>             <input type="checkbox" name="check_list[]" value="safety/security film" /> safety/security film<br>             <input type="checkbox" name="check_list[]" value="graphics" /> graphics<br>              <input type="checkbox" name="check_list[]" value="decorative film" /> decorative film<br>             <input type="checkbox" name="check_list[]" value="wall murals" /> wall murals<br></p>             <p><label for="doors">number of windows / doors:</label> <input type="text" class="form-control" name="doors" id="doors" tabindex="6" /></p>   <p><label for="hear">how did hear our company?</label> <textarea  class="form-control" name="hear" id="hear" cols="12" rows="6" tabindex="7"></textarea></p>                     <p><label for="info">additional information:</label> <textarea class="form-control" name="info" id="info" cols="12" rows="6" tabindex="8"></textarea></p>          <p><input name="estimatesubmit" type="submit" id="estimatesubmit" class="submit" value="send" tabindex="9" /></p>  </form> 

here php run form:

<?php   if(isset($_post['submit'])){//to run php script on submit if(!empty($_post['check_list'])){ // loop store , display values of individual checked checkbox. foreach($_post['check_list'] $selected){ echo $selected."</br>"; }}}     $company = filter_var($_post['company'], filter_sanitize_string); $firstname = filter_var($_post['firstname'], filter_sanitize_string); $lastname = filter_var($_post['lastname'], filter_sanitize_string); $email = filter_var($_post['email'], filter_sanitize_email); $phone = filter_var($_post['phone'], filter_sanitize_string); $street = filter_var($_post['street'], filter_sanitize_string); $city = filter_var($_post['city'], filter_sanitize_string); $state = filter_var($_post['state'], filter_sanitize_string); $zip = filter_var($_post['zip'], filter_sanitize_string); $doors = filter_var($_post['doors'], filter_sanitize_string); $hear = filter_var($_post['hear'], filter_sanitize_string); $info = filter_var($_post['info'], filter_sanitize_string);  $site_owners_email = 'email@gmail.com'; // replace own email address $site_owners_name = 'client name'; // replace name $site_owners_name_from = 'free estimate submission';  if (strlen($firstname) < 2) {     $error['firstname'] = "please enter first name"; }  if (strlen($lastname) < 2) {     $error['lastname'] = "please enter last name"; }  if (!preg_match('/^[a-z0-9&\'\.\-_\+]+@[a-z0-9\-]+\.([a-z0-9\-]+\.)*+[a-z]{2}/is', $email)) {     $error['email'] = "please enter valid email address"; }  if (strlen($phone) < 3) {     $error['phone'] = "please enter phone number."; }  if (!$error) {      require_once('phpmailer/class.phpmailer.php');     $mail = new phpmailer();      $mail->from = $email;     $mail->fromname = $site_owners_name_from;     $mail->subject = "form submission";     $mail->addaddress($site_owners_email, $site_owners_name);     $mail->ishtml(true);     $mail->body = 'the estimate form on website, 3msecurityfilm.com, has been filled out.'. '<br/><br/>'. '<b>company:</b> '. $company . '<br/><b>first name:</b> '. $firstname . '<br/><b>last name:</b> '. $lastname .'<br/><b>e-mail:</b> '. $email .'<br/><b>phone:</b> '. $phone .'<br/><b>street address:</b> '. $street .'<br/><b>city:</b> '. $city . '<br/><b>state:</b> '. $state . '<br/><b>zip:</b> '. $zip . '<br/><b>areas of interest:</b> '. $selected . '<br/><b>number of windows / doors:</b> '. $doors . '<br/><b>how did hear our company?</b> '. $hear . '<br/><b>additional information:</b> '. $info;        $mail->send();      echo "<div class='alert alert-success'  role='alert'>thanks " . $firstname . ". message has been sent.</div>";  } # end if no error else {      $response = (isset($error['firstname'])) ? "<div class='alert alert-danger'  role='alert'>" . $error['firstname'] . "</div> \n" : null;     $response .= (isset($error['email'])) ? "<div class='alert alert-danger'  role='alert'>" . $error['email'] . "</div> \n" : null;     $response .= (isset($error['phone'])) ? "<div class='alert alert-danger'  role='alert'>" . $error['phone'] . "</div>" : null;      echo $response; } # end if there error sending  ?> 

the code

// loop store , display values of individual checked checkbox. foreach($_post['check_list'] $selected){     echo $selected."</br>"; } 

seems bit odd me. displays values right, not store them. after loop, $selected have value last element of array. so, nothing stored, comment suggests.

in body of mail, you're using $selected. has arbitrary value array, or uninitialised if array empty. instead implode(', ', $_post['check_list']), joins elements of array commas in between (i.e. [4,7,8] becomes "4, 7, 8").

if still doesn't work, value isn't passed $_post. var_dump($_post) in top of file see if check_list values appear there. can include output of var dump in question if need it.


Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -