在"注册"输入带有大量文字和复选框输入的表单,我已经更改了一些不再允许我使用鼠标来检查或取消选中复选框的内容,而且我不确定是什么。
奇怪(无论如何),如果我选中任何给定的复选框并使用空格键,则复选框将根据需要选中或取消选中。
我更改了"名称"并添加了一个"值"使我的表单数据在PHP驱动的电子邮件中正确填充。我需要那些才能让PHP工作,因为我已经设置好了,但是我已经尝试回去并删除这些更改作为测试,我仍然无法使用鼠标来检查或取消选中恢复到正在运行的原始代码之后。
我错过了一些明显的东西吗?有什么建议吗?
相关网页位于:www.vg4v.com/register-your-guide-service.html
我的原始测试页(复选框工作的位置)是here
当前的HTML:
<ul class="button-list">
<!-- Available Activities Checkboxes -->
<li><input type="checkbox" name="sport[]" value="Fishing"><label for="fish">Fishing</label></li>
<li><input type="checkbox" name="sport[]" value="Fly-fishing"><label for="fly-fish">Fly Fishing</label></li>
<li><input type="checkbox" name="sport[]" value="Hunting"><label for="hunt">Hunting</label></li>
<li><input type="checkbox" name="sport[]" value="Boat Charters"><label for="charter">Boat Charters</label></li>
<li><input type="checkbox" name="sport[]" value="HIking"><label for="hike">Hiking</label></li>
<li><input type="checkbox" name="sport[]" value="Rafting or Paddling"><label for="raft">Rafting/Paddling</label></li>
<li style="width:auto;"><input type="text" name="other_sports" id="other_sports" value="" placeholder="Something we missed?"></li>
</ul>
原始HTML:
<ul class="button-list">
<li><input type="checkbox" name="sport" id="fish"><label for="fish">Fishing</label></li>
<li><input type="checkbox" name="sport" id="fly-fish"><label for="fly-fish">Fly Fishing</label></li>
<li><input type="checkbox" name="sport" id="hunt"><label for="hunt">Hunting</label></li>
<li><input type="checkbox" name="sport" id="charter"><label for="charter">Boat Charters</label></li>
<li><input type="checkbox" name="sport" id="hike"><label for="hike">Hiking</label></li>
<li><input type="checkbox" name="sport" id="raft"><label for="raft">Rafting/Paddling</label></li>
<li style="width:auto;"><input type="text" name="other-sports" id="other-sports" value="" placeholder="Other services?"></li>
</ul>
我的PHP:
<?php
if(!isset($_POST['submit']))
{
//This page should not be accessed directly. Need to submit the form.
echo "error; you need to submit the form!";
}
$company = $_POST['company'];
//top fields
$name = $_POST['name'];
$phone = $_POST['phone'];
$visitor_email = $_POST['email'];
$license = $_POST['license'];
$address = $_POST['address'];
$website = $_POST['website'];
$facebook = $_POST['facebook'];
//checkboxes
foreach($_POST['sport'] as $value) {
$sport_msg .= "$value\n";
}
$other_sports = $_POST['other_sports'];
foreach($_POST['availability'] as $value) {
$availability_msg .= "$value\n";
}
foreach($_POST['season'] as $value) {
$season_msg .= "$value\n";
}
//bottom text boxes
$equipment = $_POST['equipment'];
$veteranmessage = $_POST['veteranmessage'];
//Validate first
if(empty($company)||empty($name)||empty($visitor_email)||empty($phone)||empty($license)||empty($address)||empty($equipment))
{
echo "Name and email are mandatory!";
exit;
}
if(IsInjected($visitor_email))
{
echo "Bad email value!";
exit;
}
$email_from = 'VGFV Guide Signup';//<== Shows up in the "from" field
$email_subject = "New Guide Signup";//<== Email Subject
//Begin Email Body
$email_body = "$name has signed up from $company\n\n".
"Here is their info:\n\n".
"COMPANY NAME: $company \n\n".
"GUIDE'S NAME: $name \n\n".
"PHONE NUMBER: $phone \n\n".
"EMAIL ADDRESS: $visitor_email \n\n".
"LICENSE STATE & NUMBER: $license \n\n".
"HOME BASE: $address \n\n".
"WEBSITE: $website \n\n".
"FACEBOOK/SOCIAL MEDIA ADDRESS: $facebook \n\n".
"GUIDE SERVICES OFFERED: \n$sport_msg \n\n".
"AVAILABILITY: \n$availability_msg \n\n".
"SEASONS: \n$season_msg \n\n".
"EQUIPMENT PROVIDED: \n$equipment \n\n".
"NOTE FROM THE GUIDE: \n$veteran-message \n\n".
$to = "steve@4sdesignstudio.com";//<== update the email address
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
//Send the email!
mail($to,$email_subject,$email_body,$headers);
//done. redirect to thank-you page.
header('Location: thank-you.html');
// Function to validate against any email injection attempts
function IsInjected($str)
{
$injections = array('(\n+)',
'(\r+)',
'(\t+)',
'(%0A+)',
'(%0D+)',
'(%08+)',
'(%09+)'
);
$inject = join('|', $injections);
$inject = "/$inject/i";
if(preg_match($inject,$str))
{
return true;
}
else
{
return false;
}
}
?>
答案 0 :(得分:1)
您的复选框不再“检查” 的原因是,您需要为所有复选框添加所有id
个标签。
根据我的机器本地测试并在评论中概述。
id="fish"><label for="fish">
同时遵循其他人的相同命名约定。