Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

How to throw errors in modals using Flash Session?

Be more specific Paul please, what exactly do you want to achieve? I dont see any problem to pass flash messages via. JSON or HTML through AJAX and then dislay them.



69.5k
Accepted
answer

It should not be a problem at all. Here is made up example from my configuration using bootstrap.

// Controller
if ($this->request->isPost() AND $form->isValid($this->request->getPost())) {
    $result = $this->crudHelper->updateRecord($options);
    if ($result === true) {
        $this->flash->success($this->translations->admin->general->editSuccess);
        return $this->response->redirect($this->session->cms->previousPage);
    }
    $this->flash->error($result);
}
// Volt
{% if flash.has("success") or flash.has("warning") or flash.has("notice") or flash.has("error") %}
<div class="modal fade" tabindex="-1"" role="dialog" aria-labelledby="placeholderModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="placeholderModalLabel">Modal Heading</h4>
            </div> 
                <div class="modal-body">
                    {{ flash.output() }}
                </div> 
            <div class="modal-footer">     
                <button type="button" class="btn btn-default modal-footer-close" data-dismiss="modal">Modal button</button>
            </div>
        </div>
    </div>
</div>
<script>
    $('.modal').modal({
        show: true
    });    
</script>
{% endif %}