In my web site i have created a custom content type Challenge which contains a list of tasks that the user has to do. I have created the custom content type from the CMS itself through admin/structure/content type. I have created a custom form, , and when the user clicks submit i have made a query which insures that the node id of that challenge and the user id is associated in a Challenge table (the code is below). It works fine. Now i need to create a view which shows the challenges accepted by the user, i.e., when the user logs in and clicks on a tab(i am using quicktab) then a view appears which shows the challenges undertaken by the user. Here my code for the query:

function my_module_menu() {
  $items = array();
  $items['my_module/form'] = array(
    'title' => t('My form'),
    'page callback' => 'my_module_form',
    'access arguments' => array('access content'),
    'description' => t('My form'),
    'type' => MENU_CALLBACK,
  return $items;

function my_module_my_form($form_state) {

  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => 'Accept Challenge',
    '#submit' => array('my_module_action'),

  return $form;

function my_module_action($form, &$form_state) {

 if ($node = menu_get_object()) {
  // Get the nid
   $nid = $node->nid;
 global $user;
 if ( $user->uid ) {
 $query = db_insert('challenges')
    'cid' =>$node->nid,
    'uid' => $user->uid

Well, thats it then. Now how do i create a view to show a user their accepted challenge.


  • Where to you want show challenge? In node viewing or views?
    – Nikit
    Commented Feb 11, 2013 at 6:36
  • inside Node view
    – why
    Commented Feb 11, 2013 at 7:14

1 Answer 1

  1. For node you should load challenges data in your custom module, using next: hook_node_load and/or showing next: hook_node_view. See examples module for it: nodeapi_example.
  2. For Views you should define connection with your custom table and node, there nice example for it.
  3. For Views also you can use Data module.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.