Ajax query - area handler
Permalink 1 user found helpful
Hi, I'm having problems while creating an ajax form inside a block.
If I use the code from Andrew:
the code generated does not know the area of the block, so i can't use
as arHandle becomes null.
Is there any way to avoid this or to know the current BlockView Area inside the Block Controller?
Thanks in advance.
If I use the code from Andrew:
if ($_REQUEST['ajax'] == true) { $b = $this->getBlockObject(); $bv = new BlockView(); $bv->render($b);
the code generated does not know the area of the block, so i can't use
$this->action('vote');
as arHandle becomes null.
Is there any way to avoid this or to know the current BlockView Area inside the Block Controller?
Thanks in advance.
Yes, the problem is that the form has to appear again after submit, so that the user can submit data again.
My (ugly) solution is:
in view.php
in form tag
inside form
and in view.js, of course,
My (ugly) solution is:
in view.php
if (isset($_POST['arHandle'])) $arHandle=htmlentities($_POST['arHandle'],ENT_QUOTES);//or any other sanitize else $arHandle=$this->block->a->arHandle;
in form tag
inside form
<input type="hidden" name="arHandle" value="<?php echo $arHandle;?>" />
and in view.js, of course,
arHandle:jQuery('form input[name=arHandle]').val()
Got it. I think your solution is probably the best one -- not ugly at all!
One thing I've come to appreciate about building modules for Concrete5 (and other frameworks) is that it's not such a big deal if your code isn't perfectly architected, because you're only working with a small and self-contained portion of the system. Even if something is a little messy, it's only going to be in a couple of files and you will know how to find them.
Best of luck.
-Jordan
One thing I've come to appreciate about building modules for Concrete5 (and other frameworks) is that it's not such a big deal if your code isn't perfectly architected, because you're only working with a small and self-contained portion of the system. Even if something is a little messy, it's only going to be in a couple of files and you will know how to find them.
Best of luck.
-Jordan
I'm a little unclear on why you need to do all of that stuff with the BlockView -- if you're just displaying a form that uses ajax to submit, $this->action() should work fine. But obviously you're trying to do something else otherwise you wouldn't be having a problem :)