林採取從形式和數據發送電子郵件它使用wp_mail
,由於存在多個數據(所有數據複選框)存在顯然需要一個foreach。將foreach中的數組傳遞到foreach之外的變量中?
我不能換我的頭周圍獲得的foreach中的數據,並使用它的語句之外。
//My form data
$checks = $_POST['personalization_result'];
//Pass the foreach array into this variable and use this to mail
$checkString = '';
//For each checkbox data
foreach ($checks as $k => $v) {
var_dump ($v);
}
//Email the data
$sent = wp_mail($to, $subject, $checkString, $headers); //I have set up the other variables but its not necessary to add here just focused on $checkString
形式的片段
<form action="<?php the_permalink(); ?>" method="post">
<?php echo $checkString; ?>// Trying to see what the array is doing
<input type="hidden" name="submitted" value="1">
<p><input type="submit"></p>
<li class="option table selected">
<input type="hidden" value="0" name="personalization_result[memory_0]">
<input type="checkbox" value="1" name="personalization_result[memory_0]" id="personalization_result_memory_0" checked="checked">
</li>
<li class="option table selected">
<input type="hidden" value="0" name="personalization_result[memory_1]">
<input type="checkbox" value="1" name="personalization_result[memory_1]" id="personalization_result_memory_1" checked="checked">
</li>
對不起,如果這是一個有點noobish,但是這是我學習的要求。
聲明之外的陣列。 –
$ v = array(); ? –
你是說你想在每個循環中追加'$ v'到'$ checkString'嗎? – George