AJAX with block add/edit, specifically controller action references
Permalink 1 user found helpful
(edited this post title to be more general, seems no doc on ajax out using controller actions from outside of view.php)
gives null when used in add/edit.php (obviously where whatever is a function properly declared in controller.php).
Any idea why that would be? Trying to use it within a php script included by a block's add.php.
The action function seems properly specified in the controller.php.
Thanks!
$this->action('whatever');
gives null when used in add/edit.php (obviously where whatever is a function properly declared in controller.php).
Any idea why that would be? Trying to use it within a php script included by a block's add.php.
The action function seems properly specified in the controller.php.
Thanks!
Thanks Jordan, you're my personal hero :)
I spent almost 5 hours trying to get the ajax calls getting to work from the add and edit pages from a block.
It's a bit pitty that you have to create an additional file in the tools folder to do ajax calls (from add and edit pages), this should be fixed in the upcoming releases...
I spent almost 5 hours trying to get the ajax calls getting to work from the add and edit pages from a block.
It's a bit pitty that you have to create an additional file in the tools folder to do ajax calls (from add and edit pages), this should be fixed in the upcoming releases...
My pleasure! If you mark my response as the "best answer" (or whatever it's called), I'll get bonus karma points :)
And I agree that it's too bad you have to create a separate file (kind of goes against the whole point of using MVC and having a controller). I'm not sure if this is just an oversight or if there's something in the architecture of C5 that makes it really difficult, but you should submit it as a feature request -http://www.concrete5.org/private/features/...
-Jordan
And I agree that it's too bad you have to create a separate file (kind of goes against the whole point of using MVC and having a controller). I'm not sure if this is just an oversight or if there's something in the architecture of C5 that makes it really difficult, but you should submit it as a feature request -http://www.concrete5.org/private/features/...
-Jordan
you have to prepend the method call with action_ in your controller's method/action for this to work so for example:
runs in:
when in a block context, posting to tools is certainly fine, but that is another option :)
Some of the wrapper functions in $this->post( etc are useful, though even a request to tools runs through dispatcher so all of your stuff is available concrete5 wise.
Just another opinion, not in it for the karma :)
method="post" action="<?=$this->action('form_process_payment'); ?>">
runs in:
function action_form_process_payment(){
when in a block context, posting to tools is certainly fine, but that is another option :)
Some of the wrapper functions in $this->post( etc are useful, though even a request to tools runs through dispatcher so all of your stuff is available concrete5 wise.
Just another opinion, not in it for the karma :)
Scott,
The OP is talking about calling a method from the add/edit form, not the block's view. $this->action() doesn't work in this context (not sure why, but if you try it out yourself you'll see that nothing is outputted by $this->action() calls).
The OP is talking about calling a method from the add/edit form, not the block's view. $this->action() doesn't work in this context (not sure why, but if you try it out yourself you'll see that nothing is outputted by $this->action() calls).
you're right, glazed over that.
One could load up the block and grab and instance of the controller(and access its methods) but at that point i think the path of least resistance is in using the tools approach, which it seems we both like :)
One could load up the block and grab and instance of the controller(and access its methods) but at that point i think the path of least resistance is in using the tools approach, which it seems we both like :)
Is this a block in your site's "blocks" directory or are you creating it in a package? If the former, create a new file called "whatever.php" and put it in your site's "tools" directory. If the latter, create a new directory called "tools" inside your package's directory and put the new "whatever.php" file in there.
Then just echo out whatever you want as an AJAX response (e.g. a JSON string, a chunk of HTML, a status code, whatever), and call this via a jquery ajax request from your add/edit form.
To get the address of this file, use this (if the block is just in your site's blocks directory):
Or use this (if the block is in a package):
Note that in both cases, you're passing a string to the "getToolsURL" function that is the name of your tools file WITHOUT the ".php" extension.
Hope that helps!
-Jordan