好的,所以我有一個html表單,並使用php進行服務器端驗證,將表單中的信息作爲電子郵件發送。在我的生活中,我無法獲得表單將數據作爲數組發送。<選擇多個>不能使用html格式的php
這裏是我的html:
<select multiple name="symptoms[]">
<option value="ADHD">ADHD</option>
<option value="Insomnia">Insomnia</option>
<option value="Depression">Depression</option>
<option value="PTSD">PTSD</option>
<option value="Autism">Autism</option>
<option value="Stress">Stress</option>
<option value="Addiction">Addiction</option>
<option value="Pain">Pain/Headaches</option>
這裏是我的PHP中,我認爲問題在於:
// validation expected data exists
if(!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['symptoms']) ||
!isset($_POST['location']) ||
!isset($_POST['comment'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$symptoms = $_POST['symptoms']; // not required
$location = $_POST['location']; // not required
$comments = $_POST['comment']; // required
還有PHP的這一部分,但我不認爲'症狀'區域在這裏是一個問題...
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Symptoms: ".clean_string($symptoms)."\n";
$email_message .= "Location: ".clean_string($location)."\n";
$email_message .= "Comment: ".clean_string($location)."\n";
我一直試圖改變!isset整天和$症狀行以獲得'症狀'選擇倍數顯示在我的電子郵件數組。現在它只是在電子郵件中說「數組」。我在想也許.clean-string應該是數組而不是字符串?我完全卡住了,我試過了我能找到的所有東西,複製粘貼並修改了大約5套不同的代碼,我在stackoverflow上找到了...
'死()'不存在。我假設你的意思是'die()'; – Mike
這也是一種有趣的'clean_string()'函數。你想用這個來防止什麼? – Mike
是的,邁克,我搞砸了,謝謝。說實話,我有一些與字符串有關的問題(可能與我在工作中錯過的東西有關,PHP不是我的力量,我通常只是做前端)並找到了代碼。當我完成時,除陣列以外的所有東西都起作用,所以我只是覺得它有幫助。謝謝! – Phil