简体   繁体   中英

if empty text area on button submit will shows sucess message

I am trying to get the error message when submit button click but only from text field is get message not get message from the textarea. Here is my code.

Problem is if I submit the field without text area will shows success. Please help.

    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>

In this line:

if(empty($_POST['offered'])===true||($_POST['description']===true))

You only check if $_POST['offered'] is empty, and you check if the $_POST['description'] is true (not what you want to do). You need to perform the empty() on $_POST['description'] as well.

if(empty($_POST['offered'])===true||empty($_POST['description'])===true)

如果我给出此代码,则如果所有字段均已填写,则无法给出成功消息

 if(empty($_POST['offered'])===true||empty($_POST['description'])===true)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM