Nameax
Новичок
Здравствуйте!
Помогите пожалуйста в решении проблемы! У меня есть форма html:
Почему-то не обрабатывает поля
- Имя, Mail, Message! Просто показывает дефовое сообщение required - Заполните пожалуйста данные! Можете пожалуйста подсказать - почему так?
Помогите пожалуйста в решении проблемы! У меня есть форма html:
Код:
<?php echo $error; ?>
<form method="post" class="contact-form">
<div class="row">
<div class="form-group col-md-6 col-lg-6 col-xl-6">
<input type="text" name="name" class="form-control" placeholder="Name" required="required"/>
</div>
<div class="form-group col-md-6 col-lg-6 col-xl-6">
<input type="email" name="email" class="form-control" placeholder="Email" required="required"/>
</div>
</div>
<div class="form-group">
<textarea name="message" class="form-control" rows="9" placeholder="Message" required="required"/></textarea>
</div>
<button type="submit" name="submit" id="" class="btn btn-primary">Submit</button>
</form>
Код:
$error = '';
$name = '';
$email = '';
$message = '';
function clean_text($string)
{
$string = trim($string);
$string = stripslashes($string);
$string = htmlspecialchars($string);
return $string;
}
if(isset($_POST["submit"]))
{
if(empty($_POST["name"]))
{
$error .= '<p><label class="text-danger">Please Enter your Name</label></p>';
}
else
{
$name = clean_text($_POST["name"]);
if(!preg_match("/^[a-zA-Z ]*$/",$name))
{
$error .= '<p><label class="text-danger">Only letters and white space allowed</label></p>';
}
}
if(empty($_POST["email"]))
{
$error .= '<p><label class="text-danger">Please Enter your Email</label></p>';
}
else
{
$email = clean_text($_POST["email"]);
if(!filter_var($email, FILTER_VALIDATE_EMAIL))
{
$error .= '<p><label class="text-danger">Invalid email format</label></p>';
}
}
if(empty($_POST["message"]))
{
$error .= '<p><label class="text-danger">Message is required</label></p>';
}
else
{
$message = clean_text($_POST["message"]);
}
if($error == '')
{
require 'class/class.phpmailer.php';
$mail = new PHPMailer;
...
- Имя, Mail, Message! Просто показывает дефовое сообщение required - Заполните пожалуйста данные! Можете пожалуйста подсказать - почему так?
