我正在尝试在提交按钮点击时收到错误消息,但仅从textfield
获取来自textarea
的消息未获取消息。这是我的代码。
问题是如果我在没有textarea
的情况下提交字段,它将显示成功消息。
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 Successfully');
}
else
if (!empty($_POST['offered']) && !empty($_POST['description']))
{
?>
<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">
<input type="hidden" name="id" value="<?php echo $val->offer_id;?>">
<label class="control-label" for="inputSuccess">Offer title
</label>
<input type="text" class="form-control" name="offered" id="offered">
<label class="control-label" for="inputSuccess">Offer Description
</label>
<textarea id="description" name="description" class="form-control " rows="3" required="offer description is required">
</textarea>
<br>
<button type="submit" class="btn btn-primary">
<span>SUBMIT
</span>
</button>
</div>
</form>
答案 0 :(得分:0)
您还没有在此行中检查过空:
改变这个:
if(empty($_POST['offered'])===true||($_POST['description'])===true)
为:
if(empty($_POST['offered'])||empty(trim($_POST['description'])))
答案 1 :(得分:0)
id_rsa.pub