How do I create a variable to display error or success message? [closed]

3

How do I display error messages in a variable, for example: You have run the code all right, there you have the first message:

        if($count==1)
        {
        // PRIMEIRA MENSAGEM

            $change_profile_msg[] = "<div class='alert alert-success'>
            <button type='button' class='close' data-dismiss='alert'>&times;</button>
            <strong>Sucesso!</strong> Perfil atualizado.
            </div>";            
        }
        else
        {
            $change_profile_msg[] = "<div class='alert alert-danger'>
            <button type='button' class='close' data-dismiss='alert'>&times;</button>
            <strong>Erro ao atualizar!</strong> Não foi possível atualizar o usuario.
            </div>";
        }

There where I want to display the message:

$main_content .= ' EXIBIR MENSAGEM AQUI DENTRO APOS TUDO OCORRER BEM OU MAL NO SUBMIT DO FORMULARIO ';

It would be something like:

foreach($change_profile_msgs $change_profile_msg) {
      $main_content .= ''.$change_profile_msg;
}

something to display the message ?

    
asked by anonymous 19.12.2015 / 19:06

1 answer

1

Create a session.

Use the following javascript:

//Função responsável por exibir ou ocutar o feedback mensage
function showAlert(type, message) {
    if (message !== '') {
        if (type === '') {
            type = 'success';
        }
        $('#alert').removeClass();
        $('#alert').addClass('alert-' + type).html(message).slideDown();
        setTimeout("closeAlert()", 15000); // 15 segundos
    }
}

//chama a função para fechar o alerta quando clicado.
$(function () {
    $('#alert').click(function () {
        closeAlert();
    });
});
//
function closeAlert() {
    $('#alert').slideUp();
    $('#alert').removeClass();
}

On your php page in the head where:

       <script>
            window.onload = function () {
                showAlert('Error', 'Bem vindo, visitante');
            };

        </script>

On your php page in body:

<div id="alert"></div>

The CSS:

#alert {
    display: none;/* O alerta deve iniciar oculto */
    min-width: 300px;
    height: auto;
/*    border-radius:10px;*/
    font-family:Tahoma,Geneva,Arial,sans-serif;font-size:12px;
    font-weight: bold;
    overflow: hidden;
    /*position: fixed;*/
    position: absolute;
    left: 50%;
    margin-left: -160px;
    z-index: 999999;
    padding: 10px;
    color: #fff;
    cursor: pointer;
    top: 0;
    text-align: center;
    margin-top: 5px;
}

.alert-error {
    background:#FF5252;
    border:1px solid #f5aca6;

}

.alert-success {
    background: #0f9d58;
    border:1px solid #2ecc71;
}

Result:

    
20.12.2015 / 06:21