Having trouble with theming the input for for a content type I created in CCK.

I am using CCK 4.7 phptemplate on Drupal 4.73

The content type is called simply, "business"

Here is my phptemplate.php:

<?php
/* Pass the form template for Directory Listing through themes. added jghyde 9/24/06 */
function simplex_node_form($form) {
  if (
$form['form_id']['#value'] == 'content_business_node_form') {
    return
_phptemplate_callback('form-business', array('form' => $form));
  } else {
  return;
  }
}
?>

And the template file is called form-business.tpl.php. Inside it, I placed this code just to see if it was getting parsed:

print '<strong>The CCK form of the type Business</strong>';

And I don't get any love out of this. It does not appear to be processing the form-business.tpl.php and giving me the output in that file. Instead I still get the default form that was always there.

Does anyone have ideas on why this form is not being overridden by template.php?

Comments

Dublin Drupaller’s picture

hi jghyde,

this isn't a complete answer..but, seeing nobody else chipped in...it might spark some ideas..

the following template.php snippet loads up a business_edit.tpl.php layout file when someone is adding a new business (CCK) node.

<?php
// copy from here.....
if ((arg(0) == 'node') && (arg(1) == 'add') && (arg(2) == 'business')){
  function
phptemplate_node_form($user, $form = array()) {
  return
_phptemplate_callback('business_edit', array('user' => $user, 'form' => $form));
  }
}
// .......to here and put it in your template.php file
?>

You'll need a different snippet for when someone is EDITING a business cck node...(the cck.module uses the default node_form so you need to *only* override node_form for that specific content type).

hope that helps..

Dub

Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate

jghyde’s picture

Dub-

Thank you so much for the reply. This argument worked. Here is a modification I used:

1. I deleted the previous CCK node type and made a new one called "businesses" (In my recent version of CCK 4.7, it is referred to as content_ with the underscore, not content- with the dash. The node name is thus content_businesses.)

2. Modified your code, which was really right on in parsing the arg(x)s, and placed this into template.php. It is IMPORTANT for newbies to understand that template.php will not work if you have more than one php enclosure ( that is

<?php
 
...
?>

) or if you have any spaces or invisible characters before the <?php starting tag):

if ((arg(0) == 'node') && (arg(1) == 'add') && (arg(2) == 'content_businesses')){
  function phptemplate_node_form($user, $form = array()) {
  return _phptemplate_callback('businesses_edit', array('user' => $user, 'form' => $form));
  }
}

If you have mod_rewrite enabled, the arg() values are in the uri in the address bar of your browser. For example, http://www.example.com/node/add/content_businesses yields:

arg(0) == 'node';
arg(1) == 'add';
arg(2) == 'content_businesses';

3. Created a businesses_edit.tpl.php file and placed inside it:

<?php
print "Howdy you made it!";
?>

And guess what? I MADE IT!

Now I have to figure out what variables are available for themeing. Anyone have a quick one-liner?

Thanks Dub, you are the man!

Joe Hyde
jghyde

Dublin Drupaller’s picture

here's the template.php snippet for calling your businesses_edit.tpl.php layout file when you're EDITing a Businesses CCK node.

<?php
// copy from here.............
if ((arg(0) == 'node') && (arg(2) == 'edit')){
   
$node = node_load(array('nid' => arg(1)));
    if (
$node->type == 'content_businesses'){
      function
phptemplate_node_form($user, $form = array()) {
      return
_phptemplate_callback('businesses_edit', array('user' => $user, 'form' => $form));
      }
    }
}
// ........to here and paste it into your template.php file
?>

To answer your question about which variables are available....you'll need to check out the forms api or the Forms API Quick reference

Dub

Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate

zroger’s picture

I have gotten alot of mileage out of doing it this way. I create a module called sitemodule.module (you can call it whatever you want) that contains site-specific code that is just easier to put into a module than in the theming. Then you can just hook into form_alter and do as you will with any form. Try this:

<?php
function sitemodule_form_alter($form_id, &$form) {
  if (isset(
$form['type']) && $form['type']['#value'] == 'content-business') {

   

// modify $form any way you want here

 

}
}
?>
manocha_ak’s picture

I am intersetd in this approach... thgrough this way can i add a button in the cck input form which basically does the add funcatioanlty... that will basically make a copy (per click of button) of two cck fileds(i have one tectfiled and one dat filed) in the form itself.... mostly like multiple functionality in ccK fileds but i wnat taht on click of a button....

Any Pointers and help is really appreciated.

Related full description is here http://drupal.org/node/158097

-Abhishek
Bangalore

-Abhishek
Bangalore

mooffie’s picture

if ($form['form_id']['#value'] == 'content_business_node_form')

Shouldn't that be "content-business_node_form" (dash, not underscore) ?

It depends on what CCK version you use. The newer CCK defines the content type as "content_business" (not "content-business"); Since the latter is a valid PHP identifier, it lets you define the function theme_content_business_node_form.

put a print $form['form_id']['#value'] statemetnt at the head of that function (and you can at least see whether it gets executed).

Dublin Drupaller’s picture

was looking for something else earlier and spotted a node form template module which sounds like an add-on to help theme node forms for you.

haven't tried it, but, it sounds like something that might be useful.

Dub

Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate

manocha_ak’s picture

Can i add a button in the cck input form which basically does the add funcatioanlty... that will basically make a copy (per click of button) of two cck fileds(i have one tectfiled and one dat filed) in the form itself.... mostly like multiple functionality in ccK fileds but i wnat taht on click of a button....

Any Pointers and help is really appreciated.

Related full description is here http://drupal.org/node/158097

-Abhishek
Bangalore

-Abhishek
Bangalore

ssm2017 Binder’s picture

hello
this looks not working for drupal 6.
the theme's documentation is too much complex for me.
do you know a simple way as this one to theme cck edit forms for drupal 6 please ?

Rosamunda’s picture

+1

Rosamunda
Buenos Aires | Argentina

Jerimee’s picture

+2

aminalid’s picture

1. Register a theming function for a form in your themes template.php file

<?php
function mytheme_theme(){
  return array(
   
'content_type_node_form' => array(
     
'arguments' => array('form' => NULL),
     
'template' => 'content_type_node_form',
    ),
  );
}
?>

where content_type is the machine name of your content type

2. create a preprocess function

<?php
function mytheme_preprocess_content_type_node_form(&$vars){
 
// implementation here
}
?>

3. create a template file called content_type_node_form.tpl.php (the name is the same as the template value from step 1)

P.S. Don't forget to flush your theme registry to apply the changes.

Rosamunda’s picture

Thanks!!

Rosamunda
Buenos Aires | Argentina

joelbox-Mondial-IT’s picture

or register the theme function in a module by placing the code in the module.

Joel Box - Mondial-IT

svnindia’s picture

Thanks man,

Is there any way to give paging for node reference filed ? drupal 6

svnindia