Cara Mengubah Form Input CCK2/CCK3

webadmin's picture

Butuh waktu beberapa hari bagi saya untuk mempelajari bagaiman mengubah input form CCK khususnya CCK2 dan CCK3 yang berbeda dengan CCK1. Semoga tutorial ini dapat membantu anda. Artikel ini sudah saya terbitkan juga di Drupal.org di bagian Theming Guide (http://drupal.org/node/601646) karena saya adalah salah satu team Dokumentasi Drupal.org. Berikut ini caranya:

Spending several days for me to find out how to theming Input Form in CCK2 on Drupal 6, hope this can help you and save your time.

To theming CCK2 Input you just need:

1. Edit template.php
2. Create node-content_type-edit.tpl.php
3. Clear Cache Data before view your result: Administer-Site Building-Performance: Clear Cache Data

EXAMPLE

Suppose your content-type is: "account_registration" and you theme is "bluemarine"

1. Edit template.php, add this:
<?php

function bluemarine_theme($existing, $type, $theme, $path) {
return array(
'account_registration_node_form' => array(
'arguments' => array('form' => NULL),
'template' => 'node-account_registration-edit'
)
);
}

?>
2. Create node-account_registration-edit.tpl.php

//To REMOVE Title field
<?php unset($form['title']); ?>

Company Data
<?php
//NOTE: if you don't have Field Group then simply type:
// print drupal_render($form['field_accreg_company_name']['0']['value']);
print drupal_render($form['group_company']['field_company']['0']['value']);
print drupal_render($form['group_company']['field_street']['0']['value']);
?>

<?php print drupal_render($form); ?>
<?php
// print_r($form); //Enable this to show all Array Variables of Form
?>

HOW TO ...........

1. RENDER ONLY 1 FIELD
<?php print drupal_render($form['group_company']['field_street']['0']['value']); ?>
2. RENDER A GROUP OF FIELDS
You don't need to render fields in group one by one, just enter this code to render all fields in a group:
<?php print drupal_render($form['group_company']); ?>
3. RENDER A SELECT LIST
Almost same like render a TEXTFIELD, but avoid ['0']['value'] at the end
<?php print drupal_render($form['group_company']['field_region']); ?>
4. RENDER A FILEFIELD
Contributed by HEY_GERMANO
<?php print drupal_render($form['field_video_file']); ?>
5. REMOVE AN INPUT FIELD
You may want to disable an input form, usually you need to remove TITLE as shown below:
<?php unset($form['title']); ?>
6. HIDE AN INPUT FIELD (HIDE vs REMOVE!)
You may still want to enable an input form but need to prevent it:
<?php $form['title']['#access'] = FALSE; ?>
7. SHOW ALL VARIABLES OF FORM
You may want to know what variables available for you:
<?php print_r($form); ?>

or for better look (but very long output):

<?php
print "";
print_r($form);
print "";
?>
8. REORDER
Use ['#weight'] to reorder
$form['buttons']['#weight'] = -50; // buttons at the top
9. PRINT BUTTONS
<?php print drupal_render($form['buttons']); ?>
10. RENAMING BUTTON
What is "Submit"? You may need to write it as "Save now!", don't you?
$form['buttons']['submit']['#value'] = 'Save to Database';
11. HIDE GROUP FIELD-SET
$form['group_general']['#access'] = FALSE;
12. HIDE BUTTON
$form['buttons']['submit']['#access']= FALSE;