Custom block with forms
Permalink
Hi,
I want to create a block with a form. Is there an example for such as block?
I need something like this:
view.php
<form action="file.php">
<input ... >
[..]
</form>
I need to display form result in the block - not to redirect to a diffrent page. How to do this? Should I use the controller?
I want to create a block with a form. Is there an example for such as block?
I need something like this:
view.php
<form action="file.php">
<input ... >
[..]
</form>
I need to display form result in the block - not to redirect to a diffrent page. How to do this? Should I use the controller?
I have something like this:
view.php:
controller:
And it is not working :(
EDIT:
I have changed the name of the controller action method ("action_" prefix). It works!
view.php:
<?php defined('C5_EXECUTE') or die(_("Access Denied.")); $bt = Loader::helper('concrete/interface'); $form = Loader::helper('form'); ?> <form action="<?php echo $this->action('myMethod')?>" method="POST"> <?php echo $bt->submit(t("Ok"), 'form', 'right', 'primary'); ?> </form> if (!empty($actionAnswer)){ echo $actionAnswer; } else { echo 'No action was here'; }
controller:
<?php defined('C5_EXECUTE') or die(_("Access Denied.")); class MyAbcController extends BlockController { protected $btTable = "btBasicTest"; protected $btInterfaceWidth = "350"; protected $btInterfaceHeight = "300"; protected $outmf = ""; public function getBlockTypeName() { return t('abc'); } public function getBlockTypeDescription() { return t('A simple testing block for developers'); } public function myMethod(){ $this->set('actionAnswer', 'Your action is running...'); }
Viewing 15 lines of 16 lines. View entire code block.
And it is not working :(
EDIT:
I have changed the name of the controller action method ("action_" prefix). It works!
Yes, you have to prefix the block controller action methods with action_. You can see that guestbook block too!
<form method="post" action="<?=$this->action('form_save_entry', '#guestBookForm-'.$controller->bID)?>">
function action_form_save_entry() {
Yes, I'd recommend that you handle the data processing the controller.