I have a function (myError) that causes a message to pop up whenever you do anything... either, confirming your actions "Email has been deleted!" or telling you that something didn't work "You don't have enough money for that item!"

Problem is, I'm trying to re-design my layout, and the error message shifts everything down when it displays. So, I'm trying to figure out a way to have a space that is just blank when there is no myError message popping up, but that same space is used by the myError when there is text available.

function myError($text, $kill=0){
	echo "<br><table class='popmessage' align=center cellpadding=5>
<tr><td><center><b>$text</td></tr>
</table><br>";
	if($kill){include('footer.php');}
}

I tried using function_exists after this, but I just can't figure it out. I'm using 'popmessage' and 'blankmessage' per my CSS files. Any advice? I've been struggling with this for awhile! Thanks.

You can define the height of the td element in pixels or em.

function myError($text, $kill=0){
    echo "<br><table class='popmessage' align=center cellpadding=5>
    <tr><td style=\"height:50px;\"><center><b>$text</td></tr>
    </table><br>";
    if($kill){include('footer.php');}
    }

This is how the cell will be alwas the same height (unless you display a very long message). I prefer to use divs instead of a table.

Yes, I prefer divs as well. How would I make it work with a div?

Having the error message show as the same size isn't the issue, it's more like, I can't figure out how to have the same space blank when there is no message popping up.

I would simply make a div section with the height e.g. 1em for messages that I know will be one line height. The variable for the error message is initialized with empty string and echoed withing the error div block. When an error occurs the error message is set appropriate string and echoed withing the error div block (or sometimes ajax response changes the innerHtml of the error div block).

$errorMessage = '';

if(someErrorCondition) {

    errorMessage = 'Error text';
}

echo '<div id="error-message">' . errorMessage . '</div>';

And in your syle sheet (or inline css):

#error-message {
    height: 1em;
    /* other css declarations here*/
}

So would it look like

$errorMessage = '';
if(myError) {
     
    errorMessage = '$text';
    }
     
    echo '<div id="error-message">' . errorMessage . '</div>';

? Is that what I would be replacing the function myError in my functions.php file with?

I just can't get that to work no matter what I do... my pages go blank.

I think the div has to be in your script all the time not only when you call a function. But it is hard to tell if I do not see the code. Maybe you post the whole script.

I figured something out using jquery & fading messages :) but thanks for trying to help!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.