I am theming my Drupal forms to make them more user-friendly.

I placed this code in my template.php files to theme the photo order page:

// we register the form to the theme registry
function swb_theme(){
  return array(
    'photo_product_node_form' => array(
      'arguments' => array('form' => NULL),
      'template' => 'photo_product_node_form',
    ),
  );
}

// we pass variables to the template
function swb_preprocess_photo_product_node_form(&$vars) {
  $vars['title'] = drupal_render($vars['form']['title']);
  $vars['body'] = drupal_render($vars['form']['body_field']);
  unset($form['menu']);
  unset($form['author']);
}

...and it works perfectly (I make my modifications in photo_product_node_form.tpl.php).

I am now trying to theme my news from.

The trouble is that if I use the following code, I get an error message saying that I can only declare function swb_theme() once:

// we register the form to the theme registry
function swb_theme(){
  return array(
    'news_node_form' => array(
      'arguments' => array('form' => NULL),
      'template' => 'news_node_form',
    ),
  );
}

// we pass variables to the template
function swb_preprocess_news_node_form(&$vars) {

  $vars['title'] = drupal_render($vars['form']['title']);
  $vars['body'] = drupal_render($vars['form']['body_field']);
  unset($form['menu']);
  unset($form['author']);
}

Question: How can I theme two forms?


Background Information

I tried combing the two swb_theme functions:

function swb_theme(){
  return array(
    'photo_product_node_form' => array(
      'arguments' => array('form' => NULL),
      'template' => 'photo_product_node_form',
    ),
  );
  
    return array(
    'news_node_form' => array(
      'arguments' => array('form' => NULL),
      'template' => 'news_node_form',
    ),
  );
}

However, it only picks up the Photo_Product and the News_node.

Comments

stodge’s picture

I'm just guessing here:

function swb_theme(){
  return array(
    'photo_product_node_form' => array(
      'arguments' => array('form' => NULL),
      'template' => 'photo_product_node_form',
    ),

    'news_node_form' => array(
      'arguments' => array('form' => NULL),
      'template' => 'news_node_form',
    ),
  );
}
big_smile’s picture

That works! Thanks!

^_^