dimanche 6 septembre 2020

Hiding unfilled user php form results from being displayed without breaking open an echoed " field

I have a multiple choice entry for my users on a single page (think Twitter). They can choose either to upload:

A Message: "textarea"(called message)

An Image: "textarea"(called title), "img"

A video: "textarea"(called title), "video", "textarea"(called description)

I have everything functioning fine behind the scenes, but whenever they leave any fields empty (which is fine) it displays them in an empty state which looks bad.

I'm trying to make it so forms not entered are read as NULL from their VARIABLES in the INCLUDES and then that line is not displayed in the echoed "div".

Doing this inside an echoed tag seems impossible. I've tried all the php statements to no avail.

Any advice appreciated.

<!doctype html>
<html>
<head>
<meta crset="utf-8">
<title>Help!</title>
<link rel="stylesheet" type="text/css">
</head>
<header>
</header>
    
<body>

<style>
    .image_feed{
    max-width: 250px;
    height: auto;
    margin: 5px auto auto;
    object-fit: contain;
    color: red;
    display: block;
    overflow: inherit;
    text-align: center;
    padding-bottom: 10px;
    }
</style>

 <div id="contentFeed" style="display: block; width:350px; object:-fit: contain; background-color: green; text-align: center; padding: 1px;">   
<?php

    $post_title = include 'videos.php';
    $post_video = include 'videos.php';
    $post_video_description = include 'videos.php';

    $post_image = include 'images.php';

    $post_message = include 'messages.php';


            $result = mysqli_query($db, "SELECT * FROM user_posts ORDER BY post_id DESC;") ;

                        while ($row = mysqli_fetch_array($result)) {

                                echo "<div class='Timg_div'>";

                                if (isset($post_title)) {

                                    echo "<textarea class='title_post' placeholder='No Title Here'>".$row['post_title']. "</textarea>";
                                    }
                            else    {
                                    echo "";
                                    }       

                                if (isset($post_image)) {

                                    echo "<img src='uploads/".$row['post_image']."' class='image_feed' >";
                                    }
                            else    {
                                    echo "";
                                    }   

                                if (isset($post_message)) {

                                    echo "<textarea class='text_post' placeholder='No Message Here'>".$row['post_message']. "</textarea>";
                                    }
                            else    {
                                    echo "";
                                    }                                       

                                if (isset($post_video)) {

                                    echo "<video class='image_feed' controls='controls' muted='true' loop='true'>
                                             <source src='uploads/".$row['post_video']."' class='image_feed' type='video/mp4' width='350' height='350'/>''
                                            </video>";
                                    }
                            else    {
                                    echo "";
                                    }   

                                if (isset($post_video_description)) {

                                    echo "<textarea class='text_post' placeholder='No Description Here'>".$row['post_video_description']. "</textarea>";
                                    }
                            else    {
                                    echo "";
                                    }   
                                    echo "</div>";
                                    }

?>
</body>

</html>

Is there an equivalent to IF-ELSE-THEN I could use? So I could discover if the VARIABLE is empty for each of the five choices, choose to put it in the "div" or not then move on to the next?

Aucun commentaire:

Enregistrer un commentaire