I have create one form in .tpl file with simple html form tag. In action attribute of this form element i passed a url like 'action=savequestion'. Now in my .module file, inside hook_menu(), I am defining menu with the above url mentioned in action.

$items['savequestion'] = array(......); //like this

But when i am submitting that form defined in tpl file, It is not calling this menu item and page not found comes.

any one have idea about this? Thank you.

  • 1
    Why are you creating form in .tpl file. Rather than create it in your module file where you has created a menu item. – WaQaR Ali Aug 13 '15 at 12:51
  • OK. I have created this in tpl. Because i don't want any extra field provided by drupal out of box. So. – Viraj Aug 13 '15 at 13:06
  • I got a solution, I was on right way, I just forgot to add 'type' => 'MENU_CALLBACK' – Viraj Aug 13 '15 at 13:08
  • But it's right to create your form into module form. After creating into module file you can call it any where. – WaQaR Ali Aug 13 '15 at 13:09
  • Ya WaQar. Agree. – Viraj Aug 13 '15 at 13:11

The right way to do this if you are using a Drupal module is to set up a form using the Form API and process things within the context of a module. You can also use a contributed module such as Webform to accomplish this too, but if you want something really custom, you should not just create a form in a template file.

All of this said, make sure your "action" is set to the same path as your menu item and that after you have created your hook_menu entry you clear the cache, so your menu item becomes part of Drupal's menu registry.

| improve this answer | |
  • This is very basic way, This won't fulfill according my requirements. According to the flow, I need only one way to implement it. So i have to have follow this method. – Viraj Aug 13 '15 at 12:44
  • Neither Form API nor Webform is basic. – leymannx Aug 13 '15 at 13:03
  • Form API isn't basic i agree and i understand. What i want to convey in above comment is, We can built form using admin, I have to have built this from backend and with just one filed. – Viraj Aug 13 '15 at 13:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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