ユーザーがチェックボックス1を選択すると、2つのチェックボックスを持つフォーム(page2)があり、3ページ目のスクリプトは指示1を電子メールアドレスに送信します。チェックボックス 2 が選択されると、指示が送信されます2。
これは機能していますが、チェックボックスが1つしかチェックされていない場合、ファイル名を空にできないなどのエラーも発生します。
これはページ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>
これはページ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";
}
問題はここにあると思います:
// array with filenames to be sent as attachment
$i_allinonewebsolution=$_POST['i_allinonewebsolution'];
$i_custommade=$_POST['i_custommade'];
$files = array("$i_allinonewebsolution","$i_custommade");
implode と array_filter を使用しようとしましたが、間違っていると思います。助けてくれてありがとう。
アップデート
フォームページをjsfiddleに追加しました。最初のjsfiddleに3ページのリンクがあります