Douglas Gorni Mello Douglas Gorni Mello - 3 months ago 8
PHP Question

How to send the multiple options of the checkbox in FormMail PHP?

I have this options, where I take the all options for my FormMail PHP:

<div class="form-checkbox">
<label for="modulo-1"><input type="checkbox" class="" name="Modulo" id="modulo-1" value="Simples Led" /> Simples Led</label>
</div>
<div class="form-checkbox">
<label for="modulo-2"><input type="checkbox" class="" name="Modulo" id="modulo-2" value="Simples Solar" /> Simples Solar</label>
</div>
<div class="form-checkbox">
<label for="modulo-3"><input type="checkbox" class="" name="Modulo" id="modulo-3" value="Simples Eólico" /> Simples Eólico</label>
</div>


But, my archive PHP don't send all checked options.

This is my formMail in PHP. It create one list, but I could send all checked options in my form.

function parse_form($array) {
$reserved_keys[] = "MAX_FILE_SIZE";
$reserved_keys[] = "required";
$reserved_keys[] = "redirect";
$reserved_keys[] = "formlimpo";
$reserved_keys[] = "require";
$reserved_keys[] = "path_to_file";
$reserved_keys[] = "recipient";
$reserved_keys[] = "subject";
$reserved_keys[] = "bgcolor";
$reserved_keys[] = "text_color";
$reserved_keys[] = "link_color";
$reserved_keys[] = "vlink_color";
$reserved_keys[] = "alink_color";
$reserved_keys[] = "title";
$reserved_keys[] = "missing_fields_redirect";
$reserved_keys[] = "env_report"; $reserved_keys[] = "acao";

if (count($array)) {
while (list($key, $val) = each($array)) {
$reserved_violation = 0;
for ($ri=0; $ri<count($reserved_keys); $ri++) {
if ($key == $reserved_keys[$ri]) {
$reserved_violation = 1;
}
}
if ($reserved_violation != 1) {
if (is_array($val)) {
$contenttemp = "<b>$key:</b><br>";
for ($z=0;$zcount($val);$z++) {
$contenttemp .= "$val[$z]<br>";
}
$contenttemp .= "<br>\n";
$content .= $contenttemp;
} else {

if ($val) {
$content .= "<span style='font-family: arial; font-size: 14px;'><b>$key</b> $val</span><br><hr style='border-top: 1px solid #ccc;border-bottom: 1px solid #fff;'>\n";
}
}

}
}
}
return $content;
}

Answer

You have a Error in this Line

for ($z=0;$zcount($val);$z++) {

I think the Error "Function name must be a string" comes frome here, better:

$count_val = count($val);
for ($z=0;$z < $count_val ;$z++) {

And the right Answer is you need to do

name="modulo[]"

Or another way is this:

<div class="form-checkbox">
   <label for="modulo-1">
      <input type="checkbox" class="" name="Modulo1" id="modulo-1" value="Simples Led" /> Simples Led
   </label>
</div>
<div class="form-checkbox">
   <label for="modulo-2"> 
      <input type="checkbox" class="" name="Modulo2" id="modulo-2" value="Simples Solar" /> Simples Solar
   </label>
</div>
<div class="form-checkbox">
   <label for="modulo-3">
       <input type="checkbox" class="" name="Modulo3" id="modulo-3" value="Simples Eólico" /> Simples Eólico
   </label>
</div>