Need help to Properly echo DIV

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bgbs
Forum Newbie
Posts: 6
Joined: Thu Mar 12, 2009 11:23 am

Need help to Properly echo DIV

Post by bgbs »

I'm trying to wrap $errors in DIV, but even though error messages are not displayed it still displays the Div block.
How can I program it that it would display the div only when the error is displayed?

This is the our output:

Code: Select all

<?PHP
            echo "<div class='error-message'>";
             echo $errors;
             echo "</div>"; 
?>

I guess I can apply the div to each individual $error but when it displays all error messages, it will display them in the individual blocks. I would like them to be inclosed in one div block

Code: Select all

if ($action == "update")
    {
    if (empty($firstName)  )
        {
        $errors .= "&raquo; First Name can not be empty";
        }
    if (empty($lastName))
        {
        $errors .= "<br/>&raquo; Last Name can not be empty";
        }
    if (empty($emailAddress))
        {
        $errors .= "&raquo; Email Address can not be empty";
        }
    
    if (empty($coName))
        {
        $errors .= "&raquo; Company Name can not be empty";
        }
    if (empty($phoneOffice))
        {
        $errors .= "<div class='error-message'>&raquo; Office Phone can not be empty</div>";
        }
    
    if ($errors == "")
        {
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Need help to Properly echo DIV

Post by McInfo »

The answer is in the code you posted -- place the three echo statements in a conditional block.

Code: Select all

if ($errors != '') {
    // echo, echo, echo
}
Please use .

Edit: This post was recovered from search engine cache.
Post Reply