I used to theme CCK input form with a template file called by template.php like this:

function phptemplate_node_form($form) {
  if ($form['form_id']['#value'] == 'news_node_form') {
    return _phptemplate_callback('news_form', array('form' => $form));
  }
  if ($form['form_id']['#value'] == 'event_node_form') {
    return _phptemplate_callback('event_form', array('form' => $form));
  }

}

and than using a event_form.tpl.php file.
Everything worked since tonight when working on a new website:
The template file doesn't work and the form stay untouched.
Anybody knows if there have been changes to CCK that can cause this beahviour?
Any help appreciated.

CommentFileSizeAuthor
#4 Screenshot_1_0.png50.88 KBgruchie

Comments

dodorama’s picture

I didn't mean to post it twice.
Anyway the crazy thing is that the template for the news form works. So I'm at the point that I can't understand what's going on.
Maybe it's just too late...

dodorama’s picture

Since this issue is stopping me from completing a website I would like to put 20 $ for the guy who knows how to solve this.
Anyone willing to collaborate can contact me via my personal contact form.

dodorama’s picture

Category: support » bug

I'm still investigating on this and I discovered that the form ovverride doesn't work if the content type contains a date field.
As soon as I delete the date field from the content type the override works.
I change this to bug and I'll post a n issue to the date field module, too.

gruchie’s picture

StatusFileSize
new50.88 KB

Hi, I'm having a similar problem. Like you, I've been trying to use a template file (ficreview_edit.tpl.php) called by template.php to theme my form. So far, the code for the tpl.php file looks like this:

<div id="fanficreview-ficcontent"><fieldset class=" collapsible"><legend>Fic Stats</legend>
<div><?php print drupal_render($form['field_main_characters'])?></div>
</div>

<input type="submit" name="op" id="edit-preview" value="Preview"  class="form-submit" />
<input type="submit" name="op" id="edit-submit" value="Submit"  class="form-submit" />
<input type="submit" name="op" id="edit-delete" value="Delete"  class="form-submit" />

Now, when I try to add or edit the content type, all that displays is the related header (i.e., either "Submit Fic Review" or "Sample Fic Review Title"), the empty "Fic Stats" fieldset and the preview, submit and delete buttons. When I view the source code, only the empty <div> tags are displayed- as if Drupal has stripped the php tags completely. Bear in mind that this is code I produced after slogging through the "How To Theme CCK Input Forms" tutorial.

Now, when I put in something like this

print drupal_render($form['title']);
print drupal_render($form['group_basic_info']);

instead, the title field and the group I referenced are printed. When I put the two snippets of code together, the code above is what gets used, and the php code between the <div> tags is ignored.

I'm not a PHP developer or anything, so I'm not sure if I'm just being silly about some element of this. For clarification, I've included a screenshot of what the "Submit Fic Review" page looks like when I've put in only the first snippet of code into my tpl.php file.

gruchie’s picture

Okay, I think I've sorted this out for myself. How? I went back to the original "How to Theme CCK Input Forms" tutorial and used the template.php code suggested there, but with one or two changes:

// Add Form Start...........jghyde..
if ((arg(0) == 'node') && (arg(1) == 'add') && (arg(2) == 'ficreview')){
function phptemplate_node_form($form) {
return _phptemplate_callback('ficreview', array('user' => $user, 'form' => $form));
}
}
// Add Form End.................
// Edit Form Start...........Dublin Drupaller..
if ((arg(0) == 'node') && (arg(2) == 'edit')){
    $node = node_load(array('nid' => arg(1)));
function phptemplate_node_form($form) {
          return _phptemplate_callback('ficreview', array('user' => $user, 'form' => $form));
}
}
// Edit Form End........

If you've looked at the original code before, you may notice that my content type AND my content type .tpl.php file are named the same thing. I don't know if that did the trick, but I just thought I'd point that out.

As for the contents of my tpl.php file, I ran the following code to test that Drupal was reading and using all the php included:

<?php print("Yay, the form is working!")?>
<div>
<?php print("Or is it...?")?></div>

Then, since everything appeared to be fine, I added the following code:

<!-- Begin printing out undisturbed/unchanged elements in pretty much the order you want them displayed -->
<?php
// Print the title field
print drupal_render($form['title']);
// Print the "Basic Info" group
print drupal_render($form['group_basic_info']);
// Print the "Fic Stats" group (without editing anything). 
// I.e. uncomment the line below if you've decided to leave the "Fic Stats" group alone.
// print drupal_render($form['group_fic_stats']);
?>
<!-- End undisturbed elements -->

<!-- Begin "Fic Stats" group -->
<div id="fr-fic-stats">
	<fieldset class=" collapsible"><legend>Fic Stats</legend>
	<div id="fr-fic-stats1">
		<?php // Print the "Fic Size" field from the "Fic Stats" group
		print drupal_render($form['group_fic_stats']['field_fic_size']);
		?>
	</div>
	
	<div id="fr-fic-stats2">
		<?php // Print the "Fic Status" field from the "Fic Stats" group
		print drupal_render($form['group_fic_stats']['field_fic_status']);
		?>
	</div>
	
	<div id="fr-fic-stats3">
		<?php // Print the "Rating" field from the "Fic Stats" group
		print drupal_render($form['group_fic_stats']['field_rating']);
		?>
	</div>
</fieldset>
</div>
<!-- End "Fic Stats" group -->

And everything printed out perfectly, in the exact order I put it in, with nothing being left out. Hopefully this helps someone else - I spent quite a lot of time searching up and down and modifying things to get to this point, and it would be lovely to have saved someone else the hassle. :)

knight42’s picture

Hi
Have been using this method and it works very well, so thanks for the code. Have one small problem though? I can get all the fields to print/work perfectly, but how to do you print taxonomy fields? I have several different vocabs and i cant get them to print at all. Any idea what would be the code for that say if i have a vocab called "cartags"????? Thanks

dodorama’s picture

print_r(drupal_render($form['taxonomy']));

knight42’s picture

excellent, that works. Would you have any idea how to only print out one vocab (vocab/2)

I have several different vocabs and wanted them spaced out around the form rather than grouped together. I tried

<?php
print_r(drupal_render($form['taxonomy'] ['2'])); 
?>

and

<?php
print_r(drupal_render($form['taxonomy/2'] )); 
?>

But couldnt get either to work. Any ideas? Thanks

karens’s picture

Status: Active » Closed (won't fix)

The D5 version is no longer being supported. Sorry.