1

I want to allow my users to submit different type of content using different types of templates (like in tumblr.com where you get a specific template/form for each content)

At first, I was thinking about creating custom content types, but this is a workaround because I dont really want to make different content types (all nodes are blog posts). I just want to create different forms for the content submission.

What is the proper "Drupal way" of doing that?

3
  • 1
    How do you plan on displaying the user-submitted content? Depending on how you want to do the display, it may be much better to have multiple content types instead of a single content type. Commented Feb 5, 2013 at 10:06
  • My site is a multi user blogging site. So I really only need to use the blog post content type. But I also want my bloggers to have different templates for submitting a blog post. for example: one form for submitting a picture with a caption and one form for submitting an article with an abstract.
    – Yair Levy
    Commented Feb 5, 2013 at 13:27
  • If you found the answer yourself, please add your approach as an answer, not a comment. That will help future users of this site. Commented Feb 11, 2013 at 12:37

3 Answers 3

1

The proper way to do this in Drupal is using multiple content types, but if you want (for whatever reason) to still stick to your solution, you can write a custom module, and modify that one before rendering.

Here's an example using the default page content type and hiding the body. Use the Devel module, and dsm() to inspect the form.

function mymodule_menu() {
  $items['mymodule/add'] = array(
    'title'=> 'mymodule add',
    'description' => 'add content',
    'page callback'=>'mymodule_form',
    'access arguments' => array('add content'),
    'type'=>MENU_NORMAL_ITEM,
  );

  return $items;
}

function mymodule_form() {
    global $user;
    $node = new stdClass();
    $node->uid = $user->uid;
    $node->type = 'page';
    node_object_prepare($node);

    module_load_include('inc', 'node', 'node.pages'); 
    $form = drupal_get_form("page_node_form", $node);
    hide($form['body']);
    dsm($form);
    return drupal_render($form);
}
0
  1. Create roles for your specific users
  2. Create node form templates like this by exmaple myform-node-form.tpl.php and copy it to your themes template folder.

<?php ?> <div id="myformular"> <div> <?php print drupal_render($form['mydesiredfied1']); ?> </div> <div> <?php print drupal_render($form['mydesiredfied2']); ?> </div> <div> <?php print drupal_render($form['mydesiredfied3']); ?> </div> <div> <?php print drupal_render($form['mydesiredfied4']); ?> </div> <?php echo drupal_render_children($form)?> </div>

Then Write a small module and assign the node form templates based on your roles. I wrote something where a assigned a node form template to my forms in hook_theme. You just have to check the user roles and assign your templates. Examplecode for assigning node-form templates:

function mymodul_theme() {
    return array(
      'myform_node_form' => array(
        'arguments' => array('form' => NULL),
        'template' => 'templates/myform-node-form',
        'render element' => 'form',
      ),
}
0

Well I took a different approach -

I created some templates for the WYSIWYG editor (supported for ckeditor and tinymce) and let the users pick their preferred layout (template) for submitting via RTE. In my opinion this solution is less complicated and much more flexible and easy to implement.

thanks for the help!

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.