Javascript 如果按钮上的文本区域为空,提交将在表单验证中显示成功消息
我试图在单击提交按钮时获取错误消息,但仅从Javascript 如果按钮上的文本区域为空,提交将在表单验证中显示成功消息,javascript,php,html,arrays,forms,Javascript,Php,Html,Arrays,Forms,我试图在单击提交按钮时获取错误消息,但仅从textfield获取消息,而不是从textarea获取消息。这是我的密码。 问题是,如果我提交的字段没有textarea,它将显示成功消息 if(empty($_POST)===false) { if(empty($_POST['offered'])===true||($_POST['description'])===true) { ?>
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
}
}
}
if(空($\u POST)==false)
{
如果(空($_POST['offered'])==true | |($_POST['description'])==true)
{
?>
添加一些优惠和说明
您尚未检查此行中是否为空:
更改此项:
if(empty($_POST['offered'])===true||($_POST['description'])===true)
致:
添加一些优惠和说明
尝试以下操作…文本区域的打开和关闭标记之间没有任何空格
if(empty($_POST['offered'])===true||($_POST['description'])===true)
if(empty($_POST['offered'])||empty(trim($_POST['description'])))
<?php
if(!empty($_POST))
{
if(empty($_POST['offered']) || empty($_POST['description']))
{
?>
<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
}
}
}