我正在为具有服务器端验证的网站创建联系表单,验证适用于名称和电子邮件,但它不适用于消息字段。因此,用户只需填写姓名和电子邮件字段即可发送消息。代码如下:
PHP
<?php
if($_POST['submit']){
if(!$_POST['name']){
$error= "<br/>-Please enter your name" ;
}
if(!$_POST['email']){
$error.= "<br/>-Please enter your email" ;
}
if(!$_POST['message']){
$error.= "<br/>-Please enter message" ;
}
if ($error){
$result= "Whoops, error: $error";
}
else{
mail('mahdi.mashrafi@yahoo.com', "Contact message", "Name: ".$_POST['name']." Email: ".$_POST['email']."
Email: ".$_POST['name']."
Message : ".$_POST['message']);
{
$result= "Thankyou, Ill be in touch shortly";
}
}
}
?>
HTML
<section id = "contact">
<div class = "container">
<div class = "row">
<div class = "col-md-6 col-md-offset-3">
<h1>Contact Form</h1>
<?php echo $result; ?>
<p>Send a form a message via form below </p>
<form method = "post" role = "form">
<div class = "form-group">
<input type = "text" name = "name" class = "form-control" placeholer = "Your name" value = "<?php echo $_POST['name'];?>" >
</div>
<div class = "form-group">
<input type = "email" name = "email" class = "form-control" placeholer = "Your email" value ="<?php echo $_POST['email'];?>">
</div>
<div class = "form-group">
<textarea name = "message" rows = "5" class = "form-control" placeholder = "message"><?php echo $_POST['message']; ?> </textarea>
</div>
<input type = "submit" name = "submit" class = "btn btn-secondary" value = "send message"/>
</form>
</div>
</div >
</div>
</section>
如何在发送详细信息之前填写消息字段。
答案 0 :(得分:1)
试试这个我觉得这应该有用..
if (trim($_POST['message']) == "")
{
$error.= "<br/>-Please enter message";
}
答案 1 :(得分:0)
如果查看textarea行,则在post变量后添加了额外的空格。删除该空格:
library(combinat)
temp <- permn(c(1,2,3,4,5,6,7,8,9))
fullTable <- do.call("rbind", temp)