PHPackages                             ideaglory/flash - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Queues &amp; Workers](/categories/queues)
4. /
5. ideaglory/flash

ActiveLibrary[Queues &amp; Workers](/categories/queues)

ideaglory/flash
===============

Flash Message PHP Class

v1.0.0(1y ago)04MITPHP

Since Dec 23Pushed 1y ago1 watchersCompare

[ Source](https://github.com/ideaglory/flash)[ Packagist](https://packagist.org/packages/ideaglory/flash)[ Docs](https://ideaglory.com)[ RSS](/packages/ideaglory-flash/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

Flash Message PHP Class
=======================

[](#flash-message-php-class)

Manage Notifications, Errors, and Form Values with Sessions
-----------------------------------------------------------

[](#manage-notifications-errors-and-form-values-with-sessions)

A lightweight PHP utility for managing flash messages, form validation errors, and posted form values using PHP sessions.

Flash messages are temporary notifications (e.g., success, warnings, errors) displayed to users after an action, and are automatically cleared after a page reload. This class also supports form validation error handling and repopulating form fields with previously submitted values.

---

Features
--------

[](#features)

- **Flash messages:** Supports multiple message types (`success`, `danger`, `warning`, `info`).
- **Validation errors:** Easily manage and display form validation errors.
- **Form repopulation:** Automatically sanitize and repopulate submitted form values.
- **Session-based:** Leverages PHP sessions for temporary storage and clears data after being displayed.
- **XSS protection:** Sanitizes input values to prevent cross-site scripting (XSS).

---

Installation
------------

[](#installation)

You can install this package via [Composer](https://getcomposer.org/). Run the following command:

```
composer require ideaglory/flash
```

---

Usage
-----

[](#usage)

### **1. Setting Flash Messages**

[](#1-setting-flash-messages)

You can set success, warning, danger, or info messages.

```
$flash = new Flash();

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

$data = $flash->display();
foreach ($data['messages'] as $message) {
    echo "{$message['text']}";
}
```

**Output:**

```
Account created successfully!
```

---

### **2. Handling Form Validation Errors**

[](#2-handling-form-validation-errors)

Store validation errors and repopulate form inputs.

```
$flash = new Flash();

$flash->set(
    null,
    ['username' => 'Username is required', 'email' => 'Invalid email address'],
    ['username' => 'john_doe', 'email' => 'invalid-email']
);

$data = $flash->display();

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

// Repopulate form
echo "";
echo "";
echo "";
echo "";
```

**Output:**

```
username: Username is required
email: Invalid email address

```

---

### **3. Displaying Mixed Notifications**

[](#3-displaying-mixed-notifications)

Set and display multiple types of messages in a single request.

```
$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 "{$message['text']}";
}
```

**Output:**

```
Welcome back!
Profile updated successfully.
Failed to update password.
Verify your email address.
```

---

### **4. Clearing and Reusing Flash Data**

[](#4-clearing-and-reusing-flash-data)

The class automatically clears session data after being displayed, but you can set new data for the next request.

```
$flash = new Flash();

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

$data = $flash->display();
foreach ($data['messages'] as $message) {
    echo "{$message['text']}";
}

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

**First Page Output:**

```
Initial notification.
```

**Next Page Output:**

```
Message for the next request.
```

---

### **5. Preventing Cross-Site Scripting (XSS)**

[](#5-preventing-cross-site-scripting-xss)

The class sanitizes all posted values using `htmlspecialchars` to prevent malicious input.

```
$flash = new Flash();

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

$data = $flash->display();
echo "{$data['values']['comment']}";
```

**Output:**

```

&lt;script&gt;alert(&quot;Hacked!&quot;)&lt;/script&gt;
```

---

License
-------

[](#license)

This project is licensed under the MIT License. Feel free to use and modify it as needed.

Author
------

[](#author)

Created by [IdeaGlory](https://ideaglory.com).

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance40

Moderate activity, may be stable

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

511d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/94f498f22eec76001b6ca6757c9b8fcc17a9d94dabe9cd297d5d5efd4766c270?d=identicon)[ideaglory](/maintainers/ideaglory)

---

Top Contributors

[![ideaglory](https://avatars.githubusercontent.com/u/161056510?v=4)](https://github.com/ideaglory "ideaglory (4 commits)")

---

Tags

messagephpflashideaglory

### Embed Badge

![Health badge](/badges/ideaglory-flash/health.svg)

```
[![Health](https://phpackages.com/badges/ideaglory-flash/health.svg)](https://phpackages.com/packages/ideaglory-flash)
```

###  Alternatives

[baklysystems/laravel-chat-messenger

Laravel chat package

121.8k](/packages/baklysystems-laravel-chat-messenger)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
