Note that there are some explanatory texts on larger screens.

plurals
  1. POMultiple Checkbox Values not showing
    text
    copied!<p>I have tried doing the research through this site to correct the problem on my own, but I still can't seem to get this form to call on multiple options chosen in the check boxes provided. The code is from an online form I downloaded. None of the other exact questions on here seem to be able to help me. </p> <pre><code>FULL FORM: &lt;form id='contactus' action='&lt;?php echo $formproc-&gt;GetSelfScript(); ?&gt;' method='post' enctype="multipart/form-data" accept-charset='UTF-8'&gt; &lt;input type='hidden' name='submitted' id='submitted' value='1'/&gt; &lt;input type='hidden' name='&lt;?php echo $formproc-&gt;GetFormIDInputName(); ?&gt;' value='&lt;?php echo $formproc-&gt;GetFormIDInputValue(); ?&gt;'/&gt; &lt;input type='hidden' class='spmhidip' name='&lt;?php echo $formproc-&gt;GetSpamTrapInputName(); ?&gt;' /&gt; &lt;fieldset &gt; &lt;dl&gt; &lt;dd&gt;*Name (last, first) &lt;input type="text" name="name" size="33" value='&lt;?php echo $formproc-&gt;SafeDisplay('name') ?&gt;'&gt; &lt;span id='contactus_name_errorloc' class='error'&gt;&lt;/span&gt; &lt;/dd&gt; &lt;/dl&gt; &lt;dl&gt; &lt;dd&gt;*Email Address &lt;input type="text" name="email" size="35" value='&lt;?php echo $formproc-&gt;SafeDisplay('email') ?&gt;'&gt; &lt;span id='contactus_email_errorloc' class='error'&gt; &lt;/span&gt; &lt;/dd&gt;&lt;/dl&gt; &lt;dl&gt; &lt;dd&gt;*Construction Experience &lt;input type="radio" name="construction_experience" id="construction_experience" value="Yes&lt;?php echo $formproc-&gt;SafeDisplay('experience') ?&gt;"&gt;Yes&lt;input type="radio" name="construction_experience" id="construction_experience" value="No&lt;?php echo $formproc-&gt;SafeDisplay('experience') ?&gt;"&gt;No &lt;/dd&gt;&lt;/dl&gt; &lt;dl&gt; &lt;dd&gt;*You must have valid drivers license, please select all that apply: &lt;br /&gt; &lt;input type=checkbox name="valid_license[]" id="valid_licenseD" value="D&lt;?php echo $formproc-&gt;SafeDisplay('valid_license') ?&gt;"&gt;D license &lt;input type=checkbox name="valid_license[]" id="valid_licenseG" value="G&lt;?php echo $formproc-&gt;SafeDisplay('valid_license') ?&gt;"&gt;G license &lt;input type=checkbox name="valid_license[]" id="valid_licenseG2" value="G2&lt;?php echo $formproc-&gt;SafeDisplay('valid_license') ?&gt;"&gt;G2 license &lt;/dd&gt;&lt;/dl&gt; &lt;p&gt;&lt;strong&gt;Enter additional comments in the space provided below:&lt;/strong&gt;&lt;/p&gt; &lt;dl&gt; &lt;dd&gt; &lt;span id='contactus_message_errorloc' class='error'&gt;&lt;/span&gt;&lt;textarea name="message" id="message" cols="60" rows="8"&gt;&lt;?php echo $formproc-&gt;SafeDisplay('message') ?&gt;&lt;/textarea&gt;&lt;/dd&gt;&lt;/dl&gt; &lt;dl&gt; &lt;dd&gt;*Resume (insert attachment) &lt;input type="file" name="resume" id="resume" value="" size="30"&gt; &lt;div&gt;&lt;span class='error'&gt;&lt;?php echo $formproc-&gt;GetErrorMessage(); ?&gt;&lt;/span&gt;&lt;/div&gt; &lt;span id='contactus_photo_errorloc' class='error'&gt;&lt;/span&gt; &lt;/dd&gt;&lt;/dl&gt; &lt;p style="padding-left:60px;"&gt;&lt;input type="submit" class="button primary" value="Submit Application" /&gt; &lt;input type="reset" class="button primary" value="Clear Form" name"clear" /&gt; &lt;/fieldset&gt; &lt;/form&gt; </code></pre> <p>Here is the php that calls on the information:</p> <p>` <pre><code>require_once("class.phpmailer.php"); /* Interface to Captcha handler */ class FG_CaptchaHandler { function Validate() { return false;} function GetError(){ return '';} } /* FGContactForm is a general purpose contact form class It supports Captcha, HTML Emails, sending emails conditionally, File atachments and more. */ class FGContactForm { var $receipients; var $errors; var $error_message; var $name; var $email; var $message; var $from_address; var $form_random_key; var $conditional_field; var $arr_conditional_receipients; var $fileupload_fields; var $captcha_handler; var $mailer; function FGContactForm() { $this-&gt;receipients = array(); $this-&gt;errors = array(); $this-&gt;form_random_key = 'HTgsjhartag'; $this-&gt;conditional_field=''; $this-&gt;arr_conditional_receipients=array(); $this-&gt;fileupload_fields=array(); $this-&gt;mailer = new PHPMailer(); $this-&gt;mailer-&gt;CharSet = 'utf-8'; } function EnableCaptcha($captcha_handler) { $this-&gt;captcha_handler = $captcha_handler; session_start(); } function AddRecipient($email,$name="") { $this-&gt;mailer-&gt;AddAddress($email,$name); } function SetFromAddress($from) { $this-&gt;from_address = $from; } function SetFormRandomKey($key) { $this-&gt;form_random_key = $key; } function GetSpamTrapInputName() { return 'sp'.md5('KHGdnbvsgst'.$this-&gt;GetKey()); } function SafeDisplay($value_name) { if(empty($_POST[$value_name])) { return''; } return htmlentities($_POST[$value_name]); } function GetFormIDInputName() { $rand = md5('TygshRt'.$this-&gt;GetKey()); $rand = substr($rand,0,20); return 'id'.$rand; } function GetFormIDInputValue() { return md5('jhgahTsajhg'.$this-&gt;GetKey()); } function SetConditionalField($field) { $this-&gt;conditional_field = $field; } function AddConditionalReceipent($value,$email) { $this-&gt;arr_conditional_receipients[$value] = $email; } function AddFileUploadField($file_field_name,$accepted_types,$max_size) { $this-&gt;fileupload_fields[] = array("name"=&gt;$file_field_name, "file_types"=&gt;$accepted_types, "maxsize"=&gt;$max_size); } function ProcessForm() { if(!isset($_POST['submitted'])) { return false; } if(!$this-&gt;Validate()) { $this-&gt;error_message = implode('&lt;br/&gt;',$this-&gt;errors); return false; } $this-&gt;CollectData(); $ret = $this-&gt;SendFormSubmission(); return $ret; } function RedirectToURL($url) { header("Location: $url"); exit; } function GetErrorMessage() { return $this-&gt;error_message; } function GetSelfScript() { return htmlentities($_SERVER['PHP_SELF']); } function GetName() { return $this-&gt;name; } function GetEmail() { return $this-&gt;email; } function GetMessage() { return htmlentities($this-&gt;message,ENT_QUOTES,"UTF-8"); } </code></pre> <p>/*-------- Private (Internal) Functions -------- */</p> <pre><code>function SendFormSubmission() { $this-&gt;CollectConditionalReceipients(); $this-&gt;mailer-&gt;CharSet = 'utf-8'; $this-&gt;mailer-&gt;Subject = "Online Application from $this-&gt;name"; $this-&gt;mailer-&gt;From = $this-&gt;GetFromAddress(); $this-&gt;mailer-&gt;FromName = "thermosealinsulation.ca"; $this-&gt;mailer-&gt;AddReplyTo($this-&gt;email); $message = $this-&gt;ComposeFormtoEmail(); $textMsg = trim(strip_tags(preg_replace('/&lt;(head|title|style|script)[^&gt;]*&gt;.*?&lt;\/\\1&gt;/s','',$message))); $this-&gt;mailer-&gt;AltBody = @html_entity_decode($textMsg,ENT_QUOTES,"UTF-8"); $this-&gt;mailer-&gt;MsgHTML($message); $this-&gt;AttachFiles(); if(!$this-&gt;mailer-&gt;Send()) { $this-&gt;add_error("Failed sending email!"); return false; } return true; } function CollectConditionalReceipients() { if(count($this-&gt;arr_conditional_receipients)&gt;0 &amp;&amp; !empty($this-&gt;conditional_field) &amp;&amp; !empty($_POST[$this-&gt;conditional_field])) { foreach($this-&gt;arr_conditional_receipients as $condn =&gt; $rec) { if(strcasecmp($condn,$_POST[$this-&gt;conditional_field])==0 &amp;&amp; !empty($rec)) { $this-&gt;AddRecipient($rec); } } } } /* Internal variables, that you donot want to appear in the email Add those variables in this array. */ function IsInternalVariable($varname) { $arr_interanl_vars = array('scaptcha', 'submitted', $this-&gt;GetSpamTrapInputName(), $this-&gt;GetFormIDInputName() ); if(in_array($varname,$arr_interanl_vars)) { return true; } return false; } function FormSubmissionToMail() { $ret_str=''; foreach($_POST as $key=&gt;$value) { if(!$this-&gt;IsInternalVariable($key)) { $value = htmlentities($value,ENT_QUOTES,"UTF-8"); $value = nl2br($value); $key = ucfirst($key); // CHANGES BEGIN HERE..... // This loop looks over all the $_POST values. Need to isolate the `valid_licenses` and do something special with it. if ($key == "valid_license") { $value = implode(", ", $value); // Now $value will output as the comma-separated values list. } // CHANGES END HERE $ret_str .= "&lt;div class='label'&gt;$key :&lt;/div&gt;&lt;div class='value'&gt;$value &lt;/div&gt;\n"; } } foreach($this-&gt;fileupload_fields as $upload_field) { $field_name = $upload_field["name"]; if(!$this-&gt;IsFileUploaded($field_name)) { continue; } $filename = basename($_FILES[$field_name]['name']); $ret_str .= ""; } return $ret_str; } function ExtraInfoToMail() { $ret_str=''; $ip = $_SERVER['REMOTE_ADDR']; $ret_str = "&lt;div class='label'&gt;IP address of the submitter:&lt;/div&gt;&lt;div class='value'&gt;$ip&lt;/div&gt;\n"; return $ret_str; } function GetMailStyle() { $retstr = "\n&lt;style&gt;". "body,.label,.value { font-family:Arial,Verdana; } ". ".label {font-weight:bold; margin-top:5px; font-size:1.2em; color:#333;} ". ".value {margin-bottom:15px;font-size:1.2em;padding-left:20px;} ". "&lt;/style&gt;\n"; return $retstr; } function GetHTMLHeaderPart() { $retstr = '&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"&gt;'."\n". '&lt;html&gt;&lt;head&gt;&lt;title&gt;&lt;/title&gt;'. '&lt;meta http-equiv=Content-Type content="text/html; charset=utf-8"&gt;'; $retstr .= $this-&gt;GetMailStyle(); $retstr .= '&lt;/head&gt;&lt;body&gt;'; return $retstr; } function GetHTMLFooterPart() { $retstr ='&lt;/body&gt;&lt;/html&gt;'; return $retstr ; } function ComposeFormtoEmail() { $header = $this-&gt;GetHTMLHeaderPart(); $formsubmission = $this-&gt;FormSubmissionToMail(); $extra_info = $this-&gt;ExtraInfoToMail(); $footer = $this-&gt;GetHTMLFooterPart(); $message = $header."&lt;div class='label'&gt;Job Application Submission From thermosealinsulation.ca: &lt;/div&gt;&lt;p&gt;$formsubmission&lt;/p&gt;&lt;hr/&gt;$extra_info".$footer; return $message; } function AttachFiles() { foreach($this-&gt;fileupload_fields as $upld_field) { $field_name = $upld_field["name"]; if(!$this-&gt;IsFileUploaded($field_name)) { continue; } $filename =basename($_FILES[$field_name]['name']); $this-&gt;mailer-&gt;AddAttachment($_FILES[$field_name]["tmp_name"],$filename); } } function GetFromAddress() { if(!empty($this-&gt;from_address)) { return $this-&gt;from_address; } $host = $_SERVER['SERVER_NAME']; $from ="nobody@$host"; return $from; } function Validate() { $ret = true; //security validations if(empty($_POST[$this-&gt;GetFormIDInputName()]) || $_POST[$this-&gt;GetFormIDInputName()] != $this-&gt;GetFormIDInputValue() ) { //The proper error is not given intentionally $this-&gt;add_error("Automated submission prevention: case 1 failed"); $ret = false; } //This is a hidden input field. Humans won't fill this field. if(!empty($_POST[$this-&gt;GetSpamTrapInputName()]) ) { //The proper error is not given intentionally $this-&gt;add_error("Automated submission prevention: case 2 failed"); $ret = false; } //name validations if(empty($_POST['name'])) { $this-&gt;add_error("Please provide your name"); $ret = false; } else if(strlen($_POST['name'])&gt;50) { $this-&gt;add_error("Name is too big!"); $ret = false; } //email validations if(empty($_POST['email'])) { $this-&gt;add_error("Please provide your email address"); $ret = false; } else if(strlen($_POST['email'])&gt;50) { $this-&gt;add_error("Email address is too big!"); $ret = false; } else if(!$this-&gt;validate_email($_POST['email'])) { $this-&gt;add_error("Please provide a valid email address"); $ret = false; } //message validaions if(strlen($_POST['message'])&gt;2048) { $this-&gt;add_error("Message is too big!"); $ret = false; } //captcha validaions if(isset($this-&gt;captcha_handler)) { if(!$this-&gt;captcha_handler-&gt;Validate()) { $this-&gt;add_error($this-&gt;captcha_handler-&gt;GetError()); $ret = false; } } //file upload validations if(!empty($this-&gt;fileupload_fields)) { if(!$this-&gt;ValidateFileUploads()) { $ret = false; } } return $ret; } function ValidateFileType($field_name,$valid_filetypes) { $ret=true; $info = pathinfo($_FILES[$field_name]['name']); $extn = $info['extension']; $extn = strtolower($extn); $arr_valid_filetypes= explode(',',$valid_filetypes); if(!in_array($extn,$arr_valid_filetypes)) { $this-&gt;add_error("Valid file types are: $valid_filetypes"); $ret=false; } return $ret; } function ValidateFileSize($field_name,$max_size) { $size_of_uploaded_file = $_FILES[$field_name]["size"]/1024;//size in KBs if($size_of_uploaded_file &gt; $max_size) { $this-&gt;add_error("The file is too big. File size should be less than $max_size KB"); return false; } return true; } function IsFileUploaded($field_name) { if(empty($_FILES[$field_name]['name'])) { return false; } if(!is_uploaded_file($_FILES[$field_name]['tmp_name'])) { return false; } return true; } function ValidateFileUploads() { $ret=true; foreach($this-&gt;fileupload_fields as $upld_field) { $field_name = $upld_field["name"]; $valid_filetypes = $upld_field["file_types"]; if(!$this-&gt;IsFileUploaded($field_name)) { continue; } if($_FILES[$field_name]["error"] != 0) { $this-&gt;add_error("Error in file upload; Error code:".$_FILES[$field_name]["error"]); $ret=false; } if(!empty($valid_filetypes) &amp;&amp; !$this-&gt;ValidateFileType($field_name,$valid_filetypes)) { $ret=false; } if(!empty($upld_field["maxsize"]) &amp;&amp; $upld_field["maxsize"]&gt;0) { if(!$this-&gt;ValidateFileSize($field_name,$upld_field["maxsize"])) { $ret=false; } } } return $ret; } function StripSlashes($str) { if(get_magic_quotes_gpc()) { $str = stripslashes($str); } return $str; } /* Sanitize() function removes any potential threat from the data submitted. Prevents email injections or any other hacker attempts. if $remove_nl is true, newline chracters are removed from the input. */ function Sanitize($str,$remove_nl=true) { $str = $this-&gt;StripSlashes($str); if($remove_nl) { $injections = array('/(\n+)/i', '/(\r+)/i', '/(\t+)/i', '/(%0A+)/i', '/(%0D+)/i', '/(%08+)/i', '/(%09+)/i' ); $str = preg_replace($injections,'',$str); } return $str; } /*Collects clean data from the $_POST array and keeps in internal variables.*/ function CollectData() { $this-&gt;name = $this-&gt;Sanitize($_POST['name']); $this-&gt;email = $this-&gt;Sanitize($_POST['email']); $this-&gt;ConstructionExperience = $this-&gt;Sanitize($_POST['ConstructionExperience']); foreach ($_POST['valid_license'] as $license) { // Append each sanitized element onto valid_license[] $this-&gt;valid_license[] = $this-&gt;Sanitize($license) ; } /*newline is OK in the message.*/ $this-&gt;message = $this-&gt;StripSlashes($_POST['message']); } function add_error($error) { array_push($this-&gt;errors,$error); } function validate_email($email) { return eregi("^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$", $email); } function GetKey() { return $this-&gt;form_random_key.$_SERVER['SERVER_NAME'].$_SERVER['REMOTE_ADDR']; } } ?&gt;` </code></pre> <p>All the form returns is one option selected, even if multiple boxes are checked.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload