Cakephp - Show flash messages at different positions in the view page
Asked Answered
M

3

8

I have a view file which have two forms in it at different positions say,

one form is at the left corner and the other at the right corner.

once the form is submitted successfully , a success message is flashed using

$this->Session->setFlash();

Problem is if Form1 is triggered i want to show the message flash under Form1 ie on the left corner.

Or if Form2 is triggered i want to show the message flash under Form2 ie on the right corner.

But right now both the messages are displayed at the top because i have put in layout

<?php echo $this->Session->flash(); ?>

I want to change this but not know how to achieve this.... :'(

Multiple answered 8/2, 2013 at 4:30 Comment(0)
H
20

When you call setFlash, you can provide a key value. For example,

$this->Session->setFlash('This message is for form 1.', 'default', array(), 'form1');

Then you can print the flash above each form. It will only show up if the specified key has a value.

<?php echo $this->Session->flash('form1') ?>

You can find more information here.

Histochemistry answered 8/2, 2013 at 4:42 Comment(1)
Woww....thats fantastic....this works like a charm....thankyou @Lawrence BarsantiMultiple
D
0

remove echo $this->Session->flash(); from default.ctp

then add it to different form in different divisions

for e.g. In Form1

<div class="leftflash">
<?php echo $this->Session->flash();?>
</div>

In Form2

<div class="rightflash">
<?php echo $this->Session->flash();?>
</div>

Hope it helps

Demicanton answered 8/2, 2013 at 4:40 Comment(1)
simply putting $this->Session->flash(); wont work we would need to provide a key value as Lawrence Barsanti says...Multiple
L
0

You can do also like this

<?php echo $this->Flash->render(); ?>    

before that you need to upload flash in controller like this

$this->loadComponent('Flash');       
Lording answered 31/1, 2018 at 7:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.