在HTML表单中使用多个选择框

时间:2017-01-08 07:32:44

标签: php html forms

我是PHP编码的初学者。我正在一个沙龙的网站上工作,该网站有一个表格,用户可以通过发送电子邮件的形式预约约会,我试图从HTML表格中的多个选择框中发布值,并发送该数据电子邮件中的其他字段。其他领域正在发布。但选择框不起作用。以下是我正在使用的代码:

<?php
$clnt_name = $_POST['w_p_c_name'];
$clnt_email = $_POST['w_p_c_email'];
$clnt_phn_no = $_POST['w_p_c_number'];
$rsrvtn_date = $_POST['w_p_c_date'];
$hair_cut = $POST['opt_hair_cut'];
$colr_whl_hair = $POST['opt_colouring_whole_hair'];
$colr_retouch = $POST['opt_colouring_retouch_roots'];
$colr_highlight = $POST['opt_colouring_highlighting'];
$rebonding = $POST['opt_rebonding'];
$relax_straight = $POST['opt_relaxing_straightening'];
$perming = $POST['opt_perming'];
$threading = $POST['opt_threading'];
$bleaching = $POST['opt_bleaching'];
$manicure = $POST['opt_manicure'];
$pedicure = $POST['opt_pedicure'];
$nail = $POST['opt_nail'];
$gel_nail = $POST['opt_gel_nail'];
$massage = $POST['opt_massage'];
$scrub = $POST['opt_scrub'];
$wax_face = $POST['opt_wax_face'];
$wax_arms = $POST['opt_wax_arms'];
$wax_leg = $POST['opt_wax_leg'];
$wax_body = $POST['opt_wax_body'];
$wax_intimate = $POST['opt_wax_intimate'];
$makeup = $POST['opt_makeup'];
$hijab = $POST['opt_hijab'];
$hairstyle_blodry = $POST['opt_hairstyle_blowdry'];
$hairstyle_iron = $POST['opt_hairstyle_iron'];
$hairstyle_spcl = $POST['opt_hairstyle_special'];
$hair_trmnt = $POST['opt_hair_treatment'];
$face_cleaning = $POST['opt_face_cleaning'];
$facials = $POST['opt_facials'];
$face_trmnt = $POST['opt_face_treatments'];
$scrub_ladies = $POST['opt_scrubs_ladies'];
$massage_ladies = $POST['opt_massage_ladies'];

$data = "Name : ".$clnt_name."\nEmail : ".$clnt_email."\nPhone : ".$clnt_phn_no."\nRequested Date : ".$rsrvtn_date."\nServices Requested :\n\n".$hair_cut."\n".$colr_whl_hair."\n".$colr_retouch."\n".$colr_highlight."\n".$rebonding."\n".$relax_straight."\n".$perming."\n".$threading."\n".$bleaching."\n".$manicure."\n".$pedicure."\n".$nail."\n".$gel_nail."\n".$massage."\n".$scrub."\n".$wax_face."\n".$wax_arms."\n".$wax_leg."\n".$wax_body."\n".$wax_intimate."\n".$makeup."\n".$hijab."\n".$hairstyle_blodry."\n".$hairstyle_iron."\n".$hairstyle_spcl."\n".$hair_trmnt."\n".$face_cleaning."\n".$facials."\n".$face_trmnt."\n".$scrub_ladies."\n".$massage_ladies;

$file = "services.xlxs";

$subject = "Reservation Booking";
$mail_message1 = "Hi ".$clnt_name." We have received your request for a reservation with the following details.\n\n".$data."\n\nWe will be calling to confirm the reservation shortly.\n\nThank you";

$to_rsvtn = "reservation@uxanisalon.com";
$subject2 = "Reservation";
$mail_message2 = "There has been a new request for a reservation. Details are listed below: \n\n".$data;


file_put_contents($file, $data1 . PHP_EOL, FILE_APPEND);
file_put_contents($file, $data2 . PHP_EOL, FILE_APPEND);
file_put_contents($file, $data3 . PHP_EOL, FILE_APPEND);

mail($clnt_email, $subject, $mail_message1, "From:" . $to_rsvtn);
mail($to_rsvtn, $subject2, $mail_message2, "From:" . $to_rsvtn);
header('Location: ba-complete.html');

 ?>

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

添加HTML代码确实会有所帮助。

如果您希望PHP将$_POST['select']视为一个选项数组,只需在 select元素的名称中添加方括号,如下所示:<select name="select[]" multiple …

然后您可以在PHP脚本中访问该数组

<?php    
foreach ($_POST['select'] as $selectedOption) {
    echo $selectedOption."\n";
}
?>