simple example form in drupal 7 with everything configured correctly shows “Page not found”..Why..?











up vote
3
down vote

favorite












I have installed drupal 7 and have been trying to create a custom form. The below code which am trying has been taken from http://drupal.org/node/717722 and I have not made any changes except for .info file.



here is the my_module.info



name = My module
description = Module for form api tutorial
core = 7.x


Below is the my_module.module



<?php

/**
* This function defines the URL to the page created etc.
* See http://api.drupal.org/api/function/hook_menu/6
*/
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;
}

/**
* This function gets called in the browser address bar for:
* "http://yourhost/my_module/form" or
* "http://yourhost/?q=my_module/form". It will generate
* a page with this form on it.
*/
function my_module_form() {

// This form calls the form builder function via the
// drupal_get_form() function which takes the name of this form builder
// function as an argument. It returns the results to display the form.
return drupal_get_form('my_module_my_form');

}

/**
* This function is called the "form builder". It builds the form.
* Notice, it takes one argument, the $form_state
*/
function my_module_my_form($form_state) {

// This is the first form element. It's a textfield with a label, "Name"
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('Name'),
);
return $form;
}

?>


I have placed these two files in a *my_module* folder and placed it in sites/all/modules
After that, I enabled the module from the modules page without any errors or warnings.



Now, when I try to access this for using the url, localhost/d7/?q=my_module/form



I get a "Page not found " error..!! Why..?? What am I missing..?



Its not only for this module but also for this examples for developers module http://drupal.org/project/examples. It shows the same error.










share|improve this question


















  • 2




    Did you clear the cache at admin/config/development/performance?
    – nmc
    Feb 19 '12 at 14:30










  • Thank you so much...!! That's where I was going wrong....:)
    – akshaynhegde
    Feb 19 '12 at 14:33















up vote
3
down vote

favorite












I have installed drupal 7 and have been trying to create a custom form. The below code which am trying has been taken from http://drupal.org/node/717722 and I have not made any changes except for .info file.



here is the my_module.info



name = My module
description = Module for form api tutorial
core = 7.x


Below is the my_module.module



<?php

/**
* This function defines the URL to the page created etc.
* See http://api.drupal.org/api/function/hook_menu/6
*/
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;
}

/**
* This function gets called in the browser address bar for:
* "http://yourhost/my_module/form" or
* "http://yourhost/?q=my_module/form". It will generate
* a page with this form on it.
*/
function my_module_form() {

// This form calls the form builder function via the
// drupal_get_form() function which takes the name of this form builder
// function as an argument. It returns the results to display the form.
return drupal_get_form('my_module_my_form');

}

/**
* This function is called the "form builder". It builds the form.
* Notice, it takes one argument, the $form_state
*/
function my_module_my_form($form_state) {

// This is the first form element. It's a textfield with a label, "Name"
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('Name'),
);
return $form;
}

?>


I have placed these two files in a *my_module* folder and placed it in sites/all/modules
After that, I enabled the module from the modules page without any errors or warnings.



Now, when I try to access this for using the url, localhost/d7/?q=my_module/form



I get a "Page not found " error..!! Why..?? What am I missing..?



Its not only for this module but also for this examples for developers module http://drupal.org/project/examples. It shows the same error.










share|improve this question


















  • 2




    Did you clear the cache at admin/config/development/performance?
    – nmc
    Feb 19 '12 at 14:30










  • Thank you so much...!! That's where I was going wrong....:)
    – akshaynhegde
    Feb 19 '12 at 14:33













up vote
3
down vote

favorite









up vote
3
down vote

favorite











I have installed drupal 7 and have been trying to create a custom form. The below code which am trying has been taken from http://drupal.org/node/717722 and I have not made any changes except for .info file.



here is the my_module.info



name = My module
description = Module for form api tutorial
core = 7.x


Below is the my_module.module



<?php

/**
* This function defines the URL to the page created etc.
* See http://api.drupal.org/api/function/hook_menu/6
*/
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;
}

/**
* This function gets called in the browser address bar for:
* "http://yourhost/my_module/form" or
* "http://yourhost/?q=my_module/form". It will generate
* a page with this form on it.
*/
function my_module_form() {

// This form calls the form builder function via the
// drupal_get_form() function which takes the name of this form builder
// function as an argument. It returns the results to display the form.
return drupal_get_form('my_module_my_form');

}

/**
* This function is called the "form builder". It builds the form.
* Notice, it takes one argument, the $form_state
*/
function my_module_my_form($form_state) {

// This is the first form element. It's a textfield with a label, "Name"
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('Name'),
);
return $form;
}

?>


I have placed these two files in a *my_module* folder and placed it in sites/all/modules
After that, I enabled the module from the modules page without any errors or warnings.



Now, when I try to access this for using the url, localhost/d7/?q=my_module/form



I get a "Page not found " error..!! Why..?? What am I missing..?



Its not only for this module but also for this examples for developers module http://drupal.org/project/examples. It shows the same error.










share|improve this question













I have installed drupal 7 and have been trying to create a custom form. The below code which am trying has been taken from http://drupal.org/node/717722 and I have not made any changes except for .info file.



here is the my_module.info



name = My module
description = Module for form api tutorial
core = 7.x


Below is the my_module.module



<?php

/**
* This function defines the URL to the page created etc.
* See http://api.drupal.org/api/function/hook_menu/6
*/
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;
}

/**
* This function gets called in the browser address bar for:
* "http://yourhost/my_module/form" or
* "http://yourhost/?q=my_module/form". It will generate
* a page with this form on it.
*/
function my_module_form() {

// This form calls the form builder function via the
// drupal_get_form() function which takes the name of this form builder
// function as an argument. It returns the results to display the form.
return drupal_get_form('my_module_my_form');

}

/**
* This function is called the "form builder". It builds the form.
* Notice, it takes one argument, the $form_state
*/
function my_module_my_form($form_state) {

// This is the first form element. It's a textfield with a label, "Name"
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('Name'),
);
return $form;
}

?>


I have placed these two files in a *my_module* folder and placed it in sites/all/modules
After that, I enabled the module from the modules page without any errors or warnings.



Now, when I try to access this for using the url, localhost/d7/?q=my_module/form



I get a "Page not found " error..!! Why..?? What am I missing..?



Its not only for this module but also for this examples for developers module http://drupal.org/project/examples. It shows the same error.







drupal drupal-7 drupal-modules drupal-forms






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Feb 19 '12 at 12:36









akshaynhegde

1,46221233




1,46221233








  • 2




    Did you clear the cache at admin/config/development/performance?
    – nmc
    Feb 19 '12 at 14:30










  • Thank you so much...!! That's where I was going wrong....:)
    – akshaynhegde
    Feb 19 '12 at 14:33














  • 2




    Did you clear the cache at admin/config/development/performance?
    – nmc
    Feb 19 '12 at 14:30










  • Thank you so much...!! That's where I was going wrong....:)
    – akshaynhegde
    Feb 19 '12 at 14:33








2




2




Did you clear the cache at admin/config/development/performance?
– nmc
Feb 19 '12 at 14:30




Did you clear the cache at admin/config/development/performance?
– nmc
Feb 19 '12 at 14:30












Thank you so much...!! That's where I was going wrong....:)
– akshaynhegde
Feb 19 '12 at 14:33




Thank you so much...!! That's where I was going wrong....:)
– akshaynhegde
Feb 19 '12 at 14:33












2 Answers
2






active

oldest

votes

















up vote
0
down vote













You should write:



$items['my_module']


Where my_module is module name.

And you need to create page-my_module_my_form.tpl.php file at



sites/all/theme/your_theme/template/page-my_module_my_form.tpl.php


and in this file add code like this:



<?php

if (isset($form['submission_info']) || isset($form['navigation'])) {
print drupal_render($form['navigation']);
print drupal_render($form['submission_info']);
}

print drupal_render($form['submitted']);

?>

<?php print drupal_render_children($form); ?>


and try to run with




localhost/d7/my_module




I hope this will be useful to you






share|improve this answer






























    up vote
    0
    down vote













    I know this is late, but I do believe that you need to have the $form variable passed into your form, like so :
    function my_module_my_form($form_state, $form)...
    That way you actually have a form variable to house your form data.






    share|improve this answer





















      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














       

      draft saved


      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f9349196%2fsimple-example-form-in-drupal-7-with-everything-configured-correctly-shows-page%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      0
      down vote













      You should write:



      $items['my_module']


      Where my_module is module name.

      And you need to create page-my_module_my_form.tpl.php file at



      sites/all/theme/your_theme/template/page-my_module_my_form.tpl.php


      and in this file add code like this:



      <?php

      if (isset($form['submission_info']) || isset($form['navigation'])) {
      print drupal_render($form['navigation']);
      print drupal_render($form['submission_info']);
      }

      print drupal_render($form['submitted']);

      ?>

      <?php print drupal_render_children($form); ?>


      and try to run with




      localhost/d7/my_module




      I hope this will be useful to you






      share|improve this answer



























        up vote
        0
        down vote













        You should write:



        $items['my_module']


        Where my_module is module name.

        And you need to create page-my_module_my_form.tpl.php file at



        sites/all/theme/your_theme/template/page-my_module_my_form.tpl.php


        and in this file add code like this:



        <?php

        if (isset($form['submission_info']) || isset($form['navigation'])) {
        print drupal_render($form['navigation']);
        print drupal_render($form['submission_info']);
        }

        print drupal_render($form['submitted']);

        ?>

        <?php print drupal_render_children($form); ?>


        and try to run with




        localhost/d7/my_module




        I hope this will be useful to you






        share|improve this answer

























          up vote
          0
          down vote










          up vote
          0
          down vote









          You should write:



          $items['my_module']


          Where my_module is module name.

          And you need to create page-my_module_my_form.tpl.php file at



          sites/all/theme/your_theme/template/page-my_module_my_form.tpl.php


          and in this file add code like this:



          <?php

          if (isset($form['submission_info']) || isset($form['navigation'])) {
          print drupal_render($form['navigation']);
          print drupal_render($form['submission_info']);
          }

          print drupal_render($form['submitted']);

          ?>

          <?php print drupal_render_children($form); ?>


          and try to run with




          localhost/d7/my_module




          I hope this will be useful to you






          share|improve this answer














          You should write:



          $items['my_module']


          Where my_module is module name.

          And you need to create page-my_module_my_form.tpl.php file at



          sites/all/theme/your_theme/template/page-my_module_my_form.tpl.php


          and in this file add code like this:



          <?php

          if (isset($form['submission_info']) || isset($form['navigation'])) {
          print drupal_render($form['navigation']);
          print drupal_render($form['submission_info']);
          }

          print drupal_render($form['submitted']);

          ?>

          <?php print drupal_render_children($form); ?>


          and try to run with




          localhost/d7/my_module




          I hope this will be useful to you







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 18 '13 at 12:01









          Andrey Rudenko

          9751733




          9751733










          answered Oct 9 '12 at 5:10









          Dolly

          72722344




          72722344
























              up vote
              0
              down vote













              I know this is late, but I do believe that you need to have the $form variable passed into your form, like so :
              function my_module_my_form($form_state, $form)...
              That way you actually have a form variable to house your form data.






              share|improve this answer

























                up vote
                0
                down vote













                I know this is late, but I do believe that you need to have the $form variable passed into your form, like so :
                function my_module_my_form($form_state, $form)...
                That way you actually have a form variable to house your form data.






                share|improve this answer























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  I know this is late, but I do believe that you need to have the $form variable passed into your form, like so :
                  function my_module_my_form($form_state, $form)...
                  That way you actually have a form variable to house your form data.






                  share|improve this answer












                  I know this is late, but I do believe that you need to have the $form variable passed into your form, like so :
                  function my_module_my_form($form_state, $form)...
                  That way you actually have a form variable to house your form data.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Oct 17 '13 at 16:47









                  mechhfly

                  296




                  296






























                       

                      draft saved


                      draft discarded



















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f9349196%2fsimple-example-form-in-drupal-7-with-everything-configured-correctly-shows-page%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

                      Alcedinidae

                      Origin of the phrase “under your belt”?