I think that’s what finally everyone will come up to. So you want to perform AJAX action and result should be returned not into single div but into multiple divs or another tags. Unfortunately, form_remote_tag allows to point in only one ‘update’ parameter and this does not resolve the problem. That’s why I had to look through the web and found cool snippet code: http://www.symfony-project.com/snippets/snippet/152
It’s good explained and quite simple but I had to spent a couple of hours before it really starts to work for me (even after reading of comments to this snippet). That’s why I want to re-share it here again but with my fixes:
So first of all I have a piece of code in which I’m calling AJAX action and in my case it’s going to be form_remote_tag:
echo form_remote_tag(array(‘update’ => ”, ‘url’ => ‘sfAction/add’));
so it goes to add action and I have to define for this action the following template in which actually I’m going to update my tags:
<?php $sf_context->getResponse()->setContentType(‘text/javascript’) ?>
<?php slot(‘first_update’) ?>Successfully added<?php end_slot() ?>
<?php slot(‘second_update’) ?>Another one div is updated here<?php end_slot() ?>
Element.update(‘_feedback’, ‘<?php echo str_replace(array(“\r\n”, “\n”, “\r”), “\\n”, get_slot(‘first_update’)) ?>’);
Element.update(‘div_block’, ‘<?php echo str_replace(array(“\r\n”, “\n”, “\r”), “\\n”, get_slot(‘second_update’)) ?>’);
So in this piece of code important is setContentType(‘text/javascript’) – it means everything we put here is javascript type so we won’t need to add <script> tag, also important is str_replace stuff – that’s what I took from snippet comments but had to fix it as well coz it did not work for me.
And of course somewhere in your html code you should have defined
<div id=’_feedback’></div>
and
<div id=’div_block’></div>
So this way as much content blocks as you want can be updated. But there is limitation which is caused by lenght of javascript string. So updated blocks should be enough small and that’s sucks. So I’m still looking for more universal solution for this problem.
If you know it – you are very welcome to share it with us 🙂
Thanks guys!