Thursday, July 14, 2011

Theme Function:Template File Callback

Parent :
$items['sample'] = array(
        'title' => t('Admin'),
        'page callback' => 'drupal_get_form',
        'page arguments' => array('sample_link'),
        'access arguments' => array('access content'),
        'type' => MENU_LOCAL_TASK,
        'weight' => -9,
        'file' => 'metrics_dashboard.admin.inc'
        );
$items[sample/sample_form'] = array(
        'title' => t('Sample Form'),
        'page callback' => 'drupal_get_form',
        'page arguments' => array('sample_form'),
        'access arguments' => array('access content'),
        'type' => MENU_LOCAL_TASK,
           'weight' => -8,
        'file' => 'metrics_dashboard.admin.inc'
        );

 
 Normal Form Function Callback:
 function sample_form($form_state, $loop_count) {
  $form =array();
 
   $form['table_category'] = array(
    '#type' => 'select',
    '#options' => array(  
          'project_type' => t('Project Type'),
        'project_sub_type' => t('Project Sub Type'),
        'engagement_type' => t('Engagement Type'),
        'currency' => t('Currency'),
        'role' => t('Role'),
        'location' => t('Location'),
        'skill' => t('Skill'),
        ),
    );        
  $form['value'] = array(
    '#type' => 'textfield',
      '#size' => '15',
    );
  $form['description'] = array(
    '#type' => 'textfield',
      '#size' => '15',
    );        
    return $form;
}

Theme Callback from module file for particular form:
function sample_theme($form){

    $themes = array(
            'sample_form' => array(
                  'render element' => 'form',
                    'template' => 'sample_form_file'),

//'sample_form' is a particular form that we are goin to theme using a separate tpl file
// 'sample_form_file' is the tpl file we are calling.i.e sample_form_file.tpl.php(tpl file)

sample_form_file(TPL File):

<?php
//echo '<pre>';print_r($form);
?>
<div title="sample_form">
    <div align="center"><p><h1>Sample Form</h1></p></div>
    <hr>
    <div align="right" style="width: 100%; clear: both; padding-top:10px;">
        <div style="width: 04%; float: left;">
            <p>Category</p>
        </div>
        <div style="width: 13%; float: left;padding-top:5px;">
        <?php print drupal_render($form['category']); ?>
        </div>
    </div>
</div>

No comments:

Post a Comment