【发布时间】:2016-02-13 09:26:21
【问题描述】:
我试图在单击提交按钮时获取错误消息,但仅从文本字段获取消息而不是从文本区域获取消息。这是我的代码。
问题是如果我提交没有文本区域的字段将显示成功。请帮忙。
if(empty($_POST)===false)
{
if(empty($_POST['offered'])===true||($_POST['description']===true))
{
?>
<div class="alert alert-warning alert-dismissible text-center" role="alert">
<span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>Add some offers and descriptions
</div>
<?php
}
else
{
$title=$_POST['offered'];
$offer=$_POST['description'];
$data=array($page_id,$title,$offer);
if($data)
{
$add=add_data($data);
header('location:hotel1_galery.php?page_id=1 && msg=Add Offers Sucessfully');
}
else
{
?>
<div class="alert alert-danger alert-dismissible text-center" role="alert">
<span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span><?php echo "Add offers and descriptions "; ?></div>
<?php
}
}
}
?>
HTML
<form action="hotel1_galery.php?page_id=1" method="post" class="col-sm-4" role="form">
<div class="form-group has-info">
<label class="control-label" for="inputSuccess">Offer title
</label>
<input type="text" class="form-control" name="offered" id="offered" required>
<label class="control-label" for="inputSuccess">Offer Description
</label>
<textarea id="description" name="description" placeholder="Offer Description" class="form-control " rows="3" required>
</textarea>
<br>
<button type="submit" class="btn btn-primary">
<span>SUBMIT
</span>
</button>
</div>
</form>
【问题讨论】: