Adding External Form w/ Code
Permalink
I'm trying to add an external form to a page by simply coding it into the template, because I have several pages which use the same included file but don't share a common parent page which I would normally just have them read the blocks from.
But my form is having issues finding it's controller file it would seem.
When I check the paths using the external_form's main controller they re showing up correctly. However, when I submit the form It simply jumps back to the same page which would indicate that didn't know what the action call for my form was.
I'm sure everything else in the form is correct since if I add it the regular way everything works fine.
Any help is greatly appreciated!
But my form is having issues finding it's controller file it would seem.
$a = BlockType::getByHandle('external_form'); $a->controller->filename = "innerpage_newsletter.php"; $a->render("forms/innerpage_newsletter");
When I check the paths using the external_form's main controller they re showing up correctly. However, when I submit the form It simply jumps back to the same page which would indicate that didn't know what the action call for my form was.
I'm sure everything else in the form is correct since if I add it the regular way everything works fine.
Any help is greatly appreciated!
I've also tried it with just "view" in the render statement and get the same results.
Have you tried a named block? Often what I do is create a scrapbook called 'Shared Site Elements' and then copy a common block to the scrapbook. Then I put something like this into the template:
<?php $block = Block::getByName('header nav'); if( $block && $block->bID ) $block->display(); ?>
append your forms action method name or otherwise via =$this->action('whatever') with "action" as in action_save_form method on the block controller being save_form
It should be ok then, best to put in a print statement or something to ensure the function is being called in your controller and then work back from there.
-Scott
It should be ok then, best to put in a print statement or something to ensure the function is being called in your controller and then work back from there.
-Scott
hereNT,
Thanks, but unfortunately your method needs that block to exist somewhere previously and what I'm trying to accomplish can't have that.
ScottC,
I may be misunderstanding you but I believe I've already done this. My form action calls for $this->action('add'). In my method for the controller file I have named it action_add.
I also tried $this->action('action_add') and naming the method simply 'add' and switching what matched with what in case I misunderstood you, but no results.
Thanks anyway guys, I will keep plugging at this and if you or anyone has any other tips it would be greatly appreciated.
Thanks, but unfortunately your method needs that block to exist somewhere previously and what I'm trying to accomplish can't have that.
ScottC,
I may be misunderstanding you but I believe I've already done this. My form action calls for $this->action('add'). In my method for the controller file I have named it action_add.
I also tried $this->action('action_add') and naming the method simply 'add' and switching what matched with what in case I misunderstood you, but no results.
Thanks anyway guys, I will keep plugging at this and if you or anyone has any other tips it would be greatly appreciated.
Scott's code will work - but ONLY if you add the block through the CMS (and don't embed it directly into the page.) Unfortunately, action() URLs don't work with using the code method above to embed blocks directly into templates.
I'm encountering the same problem, custom form doesnt recognize my controller action.