By I am learning on
Hi,
my custom module generates a block that contains a form. If I keep this form function in the custom_module.module file, it is invoked. But it is not when I move it to custom_module.inc file.
function custom_module_block($op = 'list', $delta = 0, $edit = array()) {
if ($op == "list") {
// Generate listing of blocks from this module, for the admin/block page
$block = array();
$block[0]["info"] = t('Custom Block');
return $block;
}
else if ($op == 'view') {
// set up the block
$block['subject'] = t('Domestic Flights');
$block['content'] = drupal_get_form('domestic_ticket_frontend_domestic_form');
return $block;
}
} // function custom_module_block
$block['content'] = drupal_get_form('domestic_ticket_frontend_domestic_form');
How can I call this form from custom_module.inc file?
Thanks
Comments
.
<?php require_once('custom_module.inc'); ?>The server won't know it has to use that file if you don't tell it to ;)
ya, thatz true Raf and thanks
ya, thatz true Raf and thanks for the reply.
Is there a way we do it for registering paths and associate functions:
I don't know if I'm making sense here :)
Regards
.
That's right on the spot, that! If you add that to your site, just refresh caches and it'll work.
my confusion is about
my confusion is about invoking the registered path, how will I do that in my hook _block?
.
You mean you want to know the path that's been filled in?
$_GET['q']
Do make sure to take the q= out from it (paths are always q=[the path])
no, I want to know how to
no, I want to know how to invoke it?
$block['content'] = drupal_get_form('domestic_ticket_frontend_domestic_form');please check the above statement that invokes a form.
Thanks
.
Oh, if I understand correctly, you want to know how to place your block on the page you set in hook_menu?
no :) when we create a block
no :)
when we create a block through drupal API then the hook used is _block. So when
and in the above piece of code the line:
is creating a form for block content, although the content can be anything but in my case I want a form.
so here I'm calling a function 'domestic_ticket_frontend_domestic_form' using drupal_get_form().
My problem is that if I define
in .module file, it is invoked, but if I place it in .inc, it is not.
Thanks
.
Alright, I get it now. You're asking whether or not hook_block has a similar way of including files as hook_menu has, right? Well, the quick and simple answer is: nope.
$block takes several values when $op is 'list':
None of them allow including files.
The other option for altering $block, is when $op is 'view', but there's no option for files there, either. That one's just these two:
So the only way to include the file in hook_block, is by using require() / require_once() / include() / include_once() when $op is 'view'
Ah! okay. then I'll include
Ah! okay. then I'll include the .inc file.
Thanks Raf, a great help. I've taken so much time of yours. Thanks again for explaining with so much patience.
Regards