How to store </br> and n in the database, and then show in HTML when it is called?

Asked

Viewed 53 times

0

I’m storing it in the attribute off_desc the description of an offer, but even if in Textarea I insert line breaks, in the database and in HTML (When I try to collect the data), they are all shown in a single line.

Follows codes:

 <!-- Mostra na tela os dados da tabela -->
        <div class="col-md-4">
            <div class="panel panel-border-color panel-border-color-primary">
                <a href="oferta/view?id=<?= $teste['ofe_id']?>">
                    <img
                            src="<?= Yii::getAlias('@web').'/'.$teste['ofe_imagem']; ?>"
                            height="305px" width="338px"
                            onclick="visualizacao(<?= $teste['ofe_id']?>)"
                ></a>
                <div class=""><h4><?= $teste['ofe_titulo']; ?></h4></div>
                <div class="panel-body">
                    <p class="scroll" style="height: 150px"><?= $teste['ofe_desc'];?></p>
                    <!-- <button data-modal="full-success" class="btn btn-space btn-success md-trigger">Sucesso</button> -->
                </div>
            </div>
        </div>

-

<!--Textbox que recolher a descrição do item-->
<div id="div_ofe_desc">
    <label class="label-control">Descrição</label>
    <textarea name="ofe_desc" class="form-control" id="ofe_desc" rows="5" cols="30" required></textarea>
</div>

-

if (isset($_POST['ofe_titulo'])) {
        $conteudoDaImagem = Yii::$app->request->post('imagem');

        //define alguns atributos e recebe outros
        $model->ofe_emp_id      = Yii::$app->user->identity->usu_emp_id;
        $model->ofe_cliques     = 0;
        $model->ofe_visualizacao= 0;

        $model->ofe_sub_id      = $_POST['subcategoria'];
        $model->ofe_titulo      = $_POST['ofe_titulo'];
        $model->ofe_tipo_id     = $_POST['ofe_tipo_id'];
        $model->ofe_redir       = $_POST['ofe_redir'];

        if($_POST['ofe_valor_neutro'] == null || $_POST['ofe_valor_neutro'] == ''){
            $model->ofe_valor_neutro = 0;        
        }else{
            $model->ofe_valor_neutro= $_POST['ofe_valor_neutro'];
        }

        if($_POST['ofe_valor_desc'] == null || $_POST['ofe_valor_desc'] == ''){
            $model->ofe_valor_desc = 0;        
        }else{
            $model->ofe_valor_desc  = $_POST['ofe_valor_desc'];
        }

        if($_POST['ofe_valor_frete'] == null || $_POST['ofe_valor_frete'] == ''){
            $model->ofe_frete = 0;        
        }else{
            $model->ofe_frete       = $_POST['ofe_valor_frete'];
        }

        if($_POST['ofe_valor_atual'] == null || $_POST['ofe_valor_atual'] == ''){
            $model->ofe_valor_atual = 0;        
        }else{
            $model->ofe_valor_atual = $_POST['ofe_valor_atual'];
        }

        $model->ofe_desc        = $_POST['ofe_desc'];
        $model->ofe_regra       = $_POST['ofe_regra'];
        $model->ofe_status      = $_POST['Oferta']['ofe_status'];
        $model->save();

        //realiza upload da imagem da oferta e mostra a tela View
        if($model->uploadImagem()){
            $model->save();
            $this->redirect(['view', 'id' => $model->ofe_id]);
        }else{
            pe("erro");
        }


    }

As you appear.

inserir a descrição da imagem aqui

  • Did you even access the database to see what is being saved? Most likely your backend is removing the HTML before saving. Can you put your backend code where you write in the bank? Maybe it’s characteristic of your framework to do this

  • all the form part, be it Forms or Post, are in basic HTML and PHP, but I can show yes. just a moment

  • Have you tried defining the CSS property white-space with the value pre or pre-wrap? So HTML will render line breaks instead of ignoring.

  • Ever tried to save the line as outerHTML? It shows HTML, take a look if it helps.

  • 1

    I managed to solve the problem, with a Pre-wrap, thank you very much for your help!.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.