How to use materialize features in php with javascript

Asked

Viewed 215 times

0

is it possible to use materialize in a php file next to javascript ? on the return of a php function I want to issue a Materialize.Oast(); however I’m not succeeding, I already referenced the file that has all css and materialize calls in php and even then it didn’t work, I’m trying to do it this way in php file.

<?php include("../head.php"); // chamadas css e materialize

  echo '<script>Materialize.toast(" teste ", 4500, "blue rounded");</script>'
?>

1 answer

0


You can do this with session variables.

File with its function:

<?php

...
// Inicia a sessão
session_start();
// Define a variável de sessão com o título do alerta
$_SESSION['toast']['title'] = 'Teste';
// Redireciona para a index
header('Location: index.php');

index php.

<?php
    session_start();
    ...
?>

...
<script>
    // Verifica se a variável existe
    <?php if (isset($_SESSION['toast']['title'])) { ?>
        Materialize.toast(<?= $_SESSION['toast']['title'] ?>)

        // Destrói a variável
        <?php unset($_SESSION['toast']['title']); ?>
    <?php } ?>
</script>

Browser other questions tagged

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