tags:

views:

256

answers:

2

Hello im a newbie at using Drupal, and have come across a block in my progress. I have been using CCK to add new content types to my forms. I was wondering if there was any way to add to the form that is generated so that i may contain the elements and also insert visual html code like head rules etc. I have dabbled with the hook_form_alter() and it does not seem to help me in my efforts. Ive been through adjusting tpl.php files and such and have made no progress. Please if there is any one there in the inter-webs who is knowledgeable on this matter your advice would be greatly appreciated.

Here is just an example of what I would want to do within the form: 1. Contain field elements within DIV's 2. Add HTML Content into the form

A: 

If you want to customize the markup for a for you can create a theme function for it and make the form use it with hook_form_alter. This has nothing to do with CCK which is used to customize a content type so you can add additional content to a content type.

googletorp
Thank you for the response, but question? Where would the theme function exist?
Romelus96
A: 

hook_form_alter does not help you in altering an edit form containing cck fields because cck fields are added after hook_form_alter call.

You need to theme your form like this:

Create a module and put this hook implementation in it:

function mymodule_theme($existing, $type, $theme, $path) {
    'your_form_id' => array(
        'arguments' => array('form' => NULL),
        'template' => 'my_template',
     )
}

Then create a file named my_template.tpl.php in your module directory.
Now empty your cache.

In that file, you can render form elements separately, like this:

<?php
print drupal_render($form['a_form_element']);
print '<h2>blah blah blah...</h2>';
print drupal_render($form['another_form_element']);
// this one is for rendering all the remaining items, like hiddens:
print drupal_render($form);

Use devel module during development. It contains many useful tools that makes development much easier.

farzan
Thank you for your reply. Im still having problems of making the elements display on the page. I get this error message on the form page itself:Parse error: syntax error, unexpected T_DOUBLE_ARROW in .../sites/all/modules/test/test.module on line 3Conceptually not sure how that snippet would work for certain forms as opposed to every page of the site.<?phpfunction test_theme($existing, $type, $theme, $path) { 'job_submit_node_form ' => array( 'arguments' => array('form' => NULL), 'template' => 'my_template', )}Is there something im doing wrong?
Romelus96
Please paste the whole code in http://drupalbin.com/ and send back the link. I'll have a look at it.
farzan

related questions