3

I'm very new to Drupal. I've been handed over a Drupal 7 project. In the project, there's a form to create a new record into database. However it's using hook_form_alter instead of creating from scratch. The form is called as node/add/<something> as a page. Similar to first few steps of this tutorial.

I'm not sure however if this is the correct Drupal way, or should I just rewrite it into a block, as I want to have it shown on .... at least two pages?

Any suggestions?

3

The distinction is simple:

  • If you need to add some fields to an existing form, and keep all of it's original functionality (or at least most of it), use hook_form_alter.

  • If you need to create a totally new experience, put it under different path and create form from scratch, like shown in Examples for developers

  • If you feel you need totally new form under already occupied path, think again as it might cripple existing functionality.Feel free to ask more specific question then.

Then, if you want a form at 2 pages, you have 2 choices:

  • If form will be the only significant element on these pages, make it a page (or pages) with hook_menu

  • If there are supposed to be other forms, submitted independently, wrap it into a block.

| improve this answer | |
  • Thanks for the swift response, Molot. I had a clear picture of the distinctions now. Guess I will have to customize the default node add/edit form. Thus, about the choices, the form will co-exist on top of the page together of the rest of blocks. Further, on one page there would be two forms on top separated by tabs. So I think choice#2 would be a better idea? How would you suggest I wrap it into a block? Structure > Blocks? Currently I'm using a customized template to override the form page. – NineAllexis Sep 4 '13 at 8:19
  • @NineAllexis If you can draw a quick mockup of what you need, please post another question :) I don't quite get it now, and comments aren't a good place to ask and answer anyway. – Mołot Sep 4 '13 at 8:26
  • Okay! I've posted another question. Thanks for the help. drupal.stackexchange.com/questions/84558/… – NineAllexis Sep 4 '13 at 9:23

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.