PHP code example of ideaglory / flash

1. Go to this page and download the library: Download ideaglory/flash library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ideaglory / flash example snippets


$flash = new Flash();

$flash->set([
    ['text' => 'Account created successfully!', 'type' => Flash::SUCCESS]
]);

$data = $flash->display();
foreach ($data['messages'] as $message) {
    echo "<div class='alert alert-{$message['type']}'>{$message['text']}</div>";
}

$flash = new Flash();

$flash->set(
    null,
    ['username' => 'Username is ->display();

// Display errors
foreach ($data['errors'] as $field => $error) {
    echo "<div class='error'>{$field}: {$error}</div>";
}

// Repopulate form
echo "<form>";
echo "<input type='text' name='username' value='{$data['values']['username']}' />";
echo "<input type='text' name='email' value='{$data['values']['email']}' />";
echo "</form>";

$flash = new Flash();

$flash->set([
    ['text' => 'Welcome back!', 'type' => Flash::INFO],
    ['text' => 'Profile updated successfully.', 'type' => Flash::SUCCESS],
    ['text' => 'Failed to update password.', 'type' => Flash::DANGER],
    ['text' => 'Verify your email address.', 'type' => Flash::WARNING]
]);

$data = $flash->display();

foreach ($data['messages'] as $message) {
    echo "<div class='alert alert-{$message['type']}'>{$message['text']}</div>";
}

$flash = new Flash();

// Set initial message
$flash->set([
    ['text' => 'Initial notification.', 'type' => Flash::INFO]
]);

$data = $flash->display();
foreach ($data['messages'] as $message) {
    echo "<div class='alert alert-{$message['type']}'>{$message['text']}</div>";
}

// Set new data for the next page
$flash->set([
    ['text' => 'Message for the next request.', 'type' => Flash::SUCCESS]
]);

$flash = new Flash();

$flash->set(null, null, ['comment' => '<script>alert("Hacked!")</script>']);

$data = $flash->display();
echo "<textarea name='comment'>{$data['values']['comment']}</textarea>";