I was wondering what would be the best way to display informative form warning messages using CodeIgniter. Similar to the error messages thrown by CodeIgniter’s form validation, but you can still proceed with the action when a warning message is shown.
For example, at the moment, I’m creating a system that allows users to sign-up for events. Administrators can add events to the system. There are two date/times associated with each event.
- Sign-up open time: This is the date and time when people can start to sign-up for an event
- Event start time: This is when the event actually starts
Validation takes place to ensure that the ‘sign-up open time’ is before the ‘event start time’- if it’s not, an error message is shown.
However for around 95% of events, the ‘sign-up open time’ will be two days before the ‘event start time’. For the other events the difference could be much larger.
It would be desirable to show the user a warning if the difference between the two dates is larger than two days. Even if a warning message (not error message) is shown the user should still be able to proceed with their action (for example, adding a new event to the database), as long as the validation has passed.
Is there a recommended way to process and display warning messages?
I use flash_messages for this sort of stuff.
All my views have a function, so whenever I need to tell the user something – it will show up on any & all pages.
Then when you proces the form, you’ll accept it, but you’ll test for the “warning”. If the warning is found, then set a flash_message with your warning message. Whatever screen the user sees next will show them the warning.