I've created a custom content-type using GUI interface.

I need to customize the form which takes input while creating a content of the content-type. I can do this by hook_theme implementation but I'm trying to create a brand new form, and save the content's fields in database, so that it appears as a full-functional content of my content-type.

  1. How do I create a form (I know how to create forms in my custom module) that contains the fields (all, or selectively some) of my custom content-type?
  2. Most Importantly, when the form is submitted, how do I save the fields so that it appears as a brand new content-type?

I think I've made it clear, please answer, or ask me to clarify the question more if necessary...

  • I don't understand why you want do to it this way, but hook_form_alter seems to be the way to go, creating a custom entity in form_submit. Can you clarify your goal ? Because as it is, you seem to want to bypass Drupal to do exactly what it's conceived to do.
    – Countzero
    Mar 21, 2012 at 8:23
  • What if a single page in my website needs 2/3 forms to save 2/3 different content types? Can I use hook_form_alter to filter form fields per user roles or something like that?
    – Shafiul
    Mar 21, 2012 at 8:28
  • Creating many content types with only one submit ? Are you sure you can't redesign your workflow to fit better in Drupal's default one ? And yes, you can filter fields in form_alter to customise their presence based on whatever condition you want, but IMHO you're heading for something which can quickly turn into implementation hell. Just thinking about the different submit functions and their logic makes me shiver.
    – Countzero
    Mar 21, 2012 at 8:43
  • I've different submit functions, different forms for each content types. Just displaying many forms in a page
    – Shafiul
    Mar 21, 2012 at 8:46
  • If you don't mind multiple submits, then nothing can prevent you from having multiple forms on the same page, each handled separately by diffrent submit functions, as if they were on separated pages. By the way hook_theme doesn't belong in form logic, but in form presentation. You can output any form you want using drupal_get_form in your code.
    – Countzero
    Mar 21, 2012 at 8:51

1 Answer 1


node_form will give you a form for your content-type, just pass a node.object having your content-type ($node->type) and maybe something more .., plus the content-type needs to be registred already i guess

saving is handled automagically ...

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.