我在 PHP 中创建了这些表单,但它们都没有必填字段,我想让姓名、电话号码和电子邮件成为必填项。我该怎么做呢?
这是代码:
<?php
$company = $_POST['company'];
$contact = $_POST['name'];
$tel = $_POST['phone'];
$email = $_POST['email'];
$comments = $_POST['message'];
$contact_type = $_POST['contact_type'];
if ($contact_type=="1")
{
$form_desc = "Contact Request Submitted";
$to_email = "mail@burlingtongroup.net, ross.crawford@burlingtongroup.net, adam.ninnis@burlingtongroup.net";
}
else if ($contact_type=="2" || $contact_type=="3")
{
$form_desc = "Call-back Request Submitted";
$to_email = "mail@burlingtongroup.net, ross.crawford@burlingtongroup.net, adam.ninnis@burlingtongroup.net";
}
else if ($contact_type=="4")
{
$form_desc = "Training Seminar Registration";
$to_email = "adam.wonnacott@burlingtongroup.com";
}
$source_page = $_SERVER['HTTP_REFERER'];
//If no errors registred, print the success message
if(isset($_POST['Submit']))
{
global $mailer;
if($contact_type=="3")
{
$content = $form_desc.", \n\n".
"Company: ".$company."\n".
"Contact: ".$contact."\n".
"Tel: ".$tel."\n".
"Email: ".$email."\n".
"Message: ".$comments."\n";
}
else if($contact_type=="4")
{
$content = $form_desc.", \n\n".
"Company: ".$company."\n".
"Contact: ".$contact."\n".
"Email: ".$email."\n";
//echo $content;
//exit;
}
else
{
$content = $form_desc.", \n\n".
"Company: ".$company."\n".
"Contact: ".$contact."\n".
"Tel: ".$tel."\n".
"Email: ".$email."\n".
"Message: ".$comments."\n";
}
mail($to_email, $form_desc.":".$company, $content, "From: ".$email );
header('Location: '.$source_page.'?sent=1');
}
?>