I have a form(page2) with 2 checkboxes when a user selects checkbox 1 the script on the 3rd page will send instructions 1 to the emailaddress. When chkbox 2 is selected it sends instructions2.
This is working but i also get errors like filename cannot be empty when only 1 chkbox is checked.
this is the code from page 2
<form name="form" method="POST" action="instructies_verzenden2.php">
<p></p>
<input type="checkbox" name="i_allinonewebsolution" value="file_1.txt"><span class="info-image information">All-in-One Websolution</span>
<input type="checkbox" name="i_custommade" value="file_2.txt"><span class="info-image information">Custom Made</span>
<input type="hidden" name="keyfield" value="<?php echo $domeinnaam?>"><input type="hidden" name="emailadres" value="<?php echo $data2[emailadres]?>"><input type="submit" class="sub-small sub-opslaan green" value="Update gegevens">
<p></p>
</form>
this is the code from page 3
// array with filenames to be sent as attachment
$i_allinonewebsolution=$_POST['i_allinonewebsolution'];
$i_custommade=$_POST['i_custommade'];
$files = array("$i_allinonewebsolution","$i_custommade");
// preparing attachments
for($x=0;$x<count($files);$x++){
$file = fopen($files[$x],"rb");
$data = fread($file,filesize($files[$x]));
fclose($file);
$data = chunk_split(base64_encode($data));
$message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$files[$x]\"\n" .
"Content-Disposition: attachment;\n" . " filename=\"$files[$x]\"\n" .
"Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
$message .= "--{$mime_boundary}\n";
}
I think the problem is here:
// array with filenames to be sent as attachment
$i_allinonewebsolution=$_POST['i_allinonewebsolution'];
$i_custommade=$_POST['i_custommade'];
$files = array("$i_allinonewebsolution","$i_custommade");
I have tried to use implode and array_filter but i am doing that wrong i guess. Thanks for any help.
UPDATE
I have added the form pages to jsfiddle. there are 3 pages links are in the first jsfiddle