Page 1 of 1

Need help to Properly echo DIV

Posted: Fri Nov 13, 2009 12:50 pm
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 == "")
        {

Re: Need help to Properly echo DIV

Posted: Fri Nov 13, 2009 7:13 pm
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.