I am trying to learn about modules and hook menus.
I followed this tutorial. https://www.youtube.com/watch?v=bjxML7A19Zs
The My Hello Page link works and takes me to the correct page (http://localhost:8012/Adrupal/content/weee). My problem is that the textfield and title(Enter your name) does not show up. I am using Drupal 7. I have not downloaded any extra modules for this tutorial.
I always flush the cache, after every change.
File url: all/modules/hello/hello.module
function hello_menu(){
$items=array();
$items['content/weee']=array(
'title'=>'My Hello Page',
'description'=>'My Hello users',
'page callback'=>'drupal_get_form',
'page arguments'=>array('hello_showHelloForm'),
'access callback'=>'user_access',
'access arguments'=>array('access content'),
'type'=>MENU_NORMAL_ITEM
);
return $items;
}
function hello_showHelloForm($form, &$form_state, $argument){
$form=array();
$form['name']=array(
'#type'=>'textfield',
'#title'=>'Enter your name'
);
return $form;
}
I have no idea what i did wrong. Any help would be appropriated.
your callback function does not have argument supplied
function hello_showHelloForm($form, &$form_state, $argument) {}
It could happen if you have put "&" before $form:
func_name(&$form, &$form_state)
Related
I am trying to display the test data on the screen by running function test() in the pagesController. Used $this->autoRender = false for it, but it is still giving me error:
Please help me out. I think some version problem is there, but I can't figure it out. Thankyou.
Cakephp by default takes Pages controller's display actions as a home page. display function manages pages and subpages itself that is why you are getting error. Either you can change your default home page in your /config/routes.php
$routes->connect('/', ['controller' => 'Pages', 'action' => 'index']);
OR
define your test action in some other controller.
OR
Remove code from display action
class PagesController {
function display()
{
// default controller code here
// your custom code here
}
}
Hope this will work.
I am sending a link out via email to users when they register that they must click and it will automatically direct and log them into the site.
I'm getting a 404 error when trying to access this link.
Example email sent out:
www.someurl.com/custom_confirm/verify?email=test#test.com&hash=somehash
My hook menu in custom_confirm looks like this:
function custom_confirm_menu(){
$items = array();
$items['custom_confirm/verify'] = array(
'title' => 'Confirming Registration',
'page callback' => 'verify_email',
'access callback' => TRUE,
);
return $items;
}
My function
function verify_email()
Is not being invoked when I hit this URL. It's giving me a 404 and not hitting any code inside the verify_email function.
Is there something wrong with this hook_menu? I don't understand why this is not working?
I have a problem using Drupal 7 admin login in my custom theme. After creating a custom theme when I try to submit the login form, I receive the following error:
"Access denied You are not authorized to access this page."
When I revert back to a default theme (eg. Bartik), everything works fine again.
After reading a lot of solutions, I can't seem to find the right one for me. Any ideas?
EDIT:
The problem seems to be the "drupal_render(drupal_get_form('search_block_form'))" in my page.tpl.php. For my theme i need a form markup without any container, so i used this function to render the form. The solution for me was to change it like:
$form_array= drupal_get_form("user_login");
$form = drupal_render($form_array);
echo $form;
First take a look at this:
your-drupal-parh/user -if this link takes to the login form, then you just need to customize the login form.
If it doesn't help, try create a login.
Update templete.php
function themename_theme() {
$items = array();
$items['user_login'] = array(
'render element' => 'form',
'path' => drupal_get_path('theme', 'themename') . '/templates',
'template' => 'user-login',
'preprocess functions' => array(
'themename_preprocess_user_login'
),
);
return $items;
}
function themename_preprocess_user_login(&$vars) {
$vars['intro_text'] = t('Custom login form');
}
themename is the name of your theme.
path points to the path where the user-login.tpl.php file exists in your theme directory[here drupal_get_path('theme', 'themename') . '/templates' means that the user-login.tpl.php file is in the theme's template directory].
Code for user-login.tpl.php:
<p><?php print render($intro_text); ?></p>
<div class="redha-user-login-form-wrapper">
<?php print drupal_render_children($form) ?>
</div>
Clear cache and see what happens.
I am developing a Drupal module. Part of it opens a pop-up window, displays some elements in it, and uses JavaScript to transfer input back to the main page.
As this is a small window, I don't want it to display the full theme borders from the site's theme.
In Drupal 6 I was able to achieve this with the following:
function MyPopupPageHandler() {
#content = "Content...";
//Add additional content to #content;
print theme("page", #content);
}
However, Drupal 7 expects the second parameter of the theme() function to be an array, and none of the examples I've seen show how I set the main content of the page.
What I'd like is a custom page template in the module, that can be overridden by the site theme if it provides one.
I would like to know:
What elements do I need to put in the array I pass to the theme() function?
What should I call my template file?
How do I tell Drupal where to find my template, as it needs to be in the module by default?
Appreciate any help you can offer.
James
Try this
First of all create a menu in .module file
function MYMODULE_menu()
{
$items['Demo'] =array(
'title' => 'Demo Page',
'page callback' => 'demo_page', // call a function
'access arguments' => array('access content'),
);
return $items;
}
After you have create a function
function demo_page()
{
$select = db_select('node', 'n');
$select = $select->fields('n', array('id'))
->extend('PagerDefault');
$queried_nodes = $select->execute()
->fetchAllAssoc('id');
$pager = theme('pager');
return theme('demo_template', array('nodes' => $queried_nodes , 'pager' => $pager)); // call a theme or you have no pass any argument in theme to change a 'nodes'=> NULL or 'pager'=>NULL
}
after i have create a theme function
function MYMODULE_theme()
{
return array(
'demo_template' => array(
'template' => 'demo-page',//this is file name of template file
'variables' => array('nodes' => NULL,'pager' => NULL), //this is pass avarible of templates file
'path' => drupal_get_path('module', 'MYMODULE_NAME').'/template' // set a path of file
),
);
}
after you have create file name like demo-page.tpl.php in sites/all/modules/MYMODULENAME/template/
and clear caches
1) The second parameter of theme() function must be an associative array. Your function should look like :
function MYMODULE_custom_function() {
$content = "Some stuff";
return theme('MYMODULE_custom_output', array('content' => $content));
}
2) I guess you meant "Where should I call my template file?" In the hook_theme() function in your same .module file :
function MYMODULE_theme() {
return array(
'MYMODULE_custom_output' => array(
'variables' => array('content' => array()),
// You can also use template file here : 'template' => 'MYMODULE-template'
// OR use the following theme_function() if you don't want to create a new file
),
);
}
// If you don't use template file
function theme_MYMODULE_custom_output($variables) {
$output = // Arrange your html output here
return $output;
}
3) To tell where to find your custom template file if you decide to use one, you can read this : https://drupal.org/node/715160 and I hope it will help.
Please stay indulgent because I'm still new with Drupal and I did try to do my best here :o)
made a simple thankyou page (e.g. /product/3/thankyou) based on a menu callback in a custom module. the content shows up fine in the normal page layout but i want the regions and blocks to show up and they don't. suggestions?
// menu callback
function custom_menu() {
$items = array();
$items['product/%/thankyou'] = array(
'page callback' => 'custom_product_thankyou',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK
);
return $items;
}
// theme function
function custom_theme() {
return array(
'product_review_thankyou' => array(
'variables' => array('node' => NULL),
'template' => 'product_review_thankyou',
),
);
}
// page callback
function custom_product_thankyou() {
$node = node_load(arg(1));
$output = theme('product_review_thankyou', array('node' => $node));
return $output;
}
I just tried your code in a drupal installation and i have no issues with missing blocks. Is it possible that you configured your blocks to be displayed only on certain pages?
The one block that i still couldn't get to show up (no matter what the block visibility settings were) was a 'menu block'. Problem was there wasn't a link for the thank you page in this block. So, I ended up having to add links on the configuration page with paths like product/[node_id]/thankyou, and then I disabled the links so they wouldn't be visible. Refreshed the page, and the block appeared.
To me this is a little annoying, as I kind of wanted this to be dynamic and not have to write in the product node ids. But either way, problem solved.