Closed (fixed)
Project:
Content Construction Kit (CCK)
Version:
4.7.x-1.x-dev
Component:
content.module
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
2 May 2006 at 18:46 UTC
Updated:
23 Jul 2008 at 14:57 UTC
Comments
Comment #1
Barry Pretsell commentedMe too, I have a large list of fields and I'd also like to group them. So does anyone know if this is possible or in the pipeline?
Comment #2
Nick Lewis commentedSuper easy folks:
First, add the following code to your template.php file (make one, if you haven't).
Now create a file called node_form.tpl.php. Let's assume you only wanted two fields, one named Frank, the other Sue. Do this
print_r(form_render($form['field_frank']));print_r(form_render($form['field_sue']));print_r(form_render($form));Does this answer your question?
Comment #3
talltim commentedThanks for the tip - I have a number of different CCK content types and therefore a number of different forms, a couple of which share fields. How do I theme these forms individually, as they'll need different fieldsets etc?
Comment #4
rory-- commentedCheck out Contemplate.module: worked like a charm for me.
Comment #5
talltim commentedDoes this allow me to theme forms? Looking at the module docs and README, it looks like it's only intended to theme nodes/teasers - something I'm already doing with custom node-content-xxx.tpl.php files.
Comment #6
introfini commentedThey are both great ideas but for different stages.
- The technique by Nick Lewis is the one to use when you want to theme the form that creates the node (the ones that the users will be getting when inserting data).
- The contemplate.module is the one to use when theming the presentation of the node created . It’s also a fast way to find out the name of the fields available to you.
Hope this helps.
Comment #7
Coldice4678 commentedWhat happens if you have maybe 3 cck modules, but you want to use one form to insert all the data in.
After On the same form, be allowed to insert data into one cck module EX:Video inventory, one module dedicated to Director (which you input once in the form) and a dedicated module for films (which you can input x amount of films on the same form)
Comment #8
heine commentedAs http://drupal.org/node/69472 explains (and hopefully fixes) CCK forms can only be themed via the general node_form callback, not via their form_id because a dash (-) is not valid in function names.
Comment #9
Patrick Nelson commented@Nick,
How do you use your solution without then breaking all the other node submission forms such as story, page, etc?
Comment #10
heine commentedTest the id of the form in the theme hook($form['form_id']['#value']) and only when it is a specific CCK form pass it through your theme code, otherwise just return / print nothing or call theme_node_form($form).
Comment #11
Patrick Nelson commentedHeine,
Can you possibly give me a more specific example, as in showing me the code and where it goes?
Regards
Patrick
Comment #12
heine commentedSuppose I have a CCK form of the node type aangeboden, then it's (broken) form_id will be content-aangeboden_node_form. The following code in template.php checks the form_id of every passed form and uses form-aangeboden.tpl.php only when the cck form 'aangeboden' needs to be styled. Other nodetypes will be displayed by the default theme. If you want to aspecifically route cck forms through themeing code, you can use the full arsenal of php functions to determine whether the form_id contains 'content-' .
then in form-aangeboden.tpl.php (you probably want to do something more exciting):
Comment #13
Patrick Nelson commentedThat works just great, Heine. Thanks a lot.
Regards
Patrick
Comment #14
Patrick Nelson commentedOne more question... :)
I notice that Nick's use of form_render (i.e,
print_r(form_render($form['field_frank']));) renders all the form elements. In other words, it displays the label and the associated help text as well as the actual form element (textfield, etc).Is there another function that can be used to split these elements up? I would prefer to be able to display the label and the form element seperately for example rather than in the standard Drupal way. But only for the form for this one particular content type. I'm happy to leave the other forms 'as-is'.
Any ideas?
Comment #15
heine commentedSure, as long as you know what the fields are named (use var_dump($form['the key']) to find out.
Very stupid, hackish example that pulls out the description underneath the Author name box on the story submission form and displays it somewhere else:
Not sure whether this always generates nice HTML. But you can of course override the different theme_elements as well.
Comment #16
Patrick Nelson commentedFurther question - I've followed all the steps in here and come to the realisation that I have absolutely no idea how to render the form buttons (submit, etc.).
Any help, anyone? Please!
Comment #17
karens commentedUse form_render($form[field_name]) for each individual field you want to use, then finish the whole thing up with form_render($form) which will finish things up and display all the parts of the form that were not displayed already, like the submit buttons.
Comment #18
Patrick Nelson commentedThank you Karen, that works just fine.
Regards
Patrick
Comment #19
jonbob commentedThe form IDs are changed now; the hack should no longer be necessary.
Comment #20
(not verified) commentedComment #21
ncameron commentedI have been referring to this thread for the past couple of hours as I get to grips with theming forms. This might come in useful for fellow php amatures. The code below explains how to change the size of a text field. This would desirable if you only want the user input one number or a zip code or another short piece of info. Let me know if there are any errors below.
Comment #22
ncameron commentedJust renaming the issue with its orignal name after I accidently changed it. Ahem. (looks around and quickly makes for the door).
Comment #23
jghyde commentedUsing CCK 4.7
CCK node content name is "business"
I presume the node name is "content_business" because when looking at the content.module code, it formats with content_ in lieu of content-
Here is the template.php contents:
and the template file is form-business.tpl.php. In it is simply:
This renders a blank page whenever you submit a login and other blank pages after submitting forms. If I delete the template.php file, the problem goes away.
What is wrong with my code?
Comment #24
jghyde commentedThe problem with the blank page is solved.
Blank page and template,php problem is caused by having any space, character, gremlins, or etc BEFORE the opening "<?". Get rid of the white space and it works.
BUT, it still does not appear to intercept the content_business input form so I can theme it. I get the default, standard form un-themed.
joeh
Comment #25
jghyde commentedMore details on themeing forms generated by CCK, and another example, is available here: http://drupal.org/node/85908
Comment #26
ryivhnn commentedAnd just to be a pain in the system, on my end finishing things up with
print form_render($form)dumps in everything that wasn't already dumped BUT things like authoring information etc come up as just text rather than links. Is that normal or have I missed something blatantly obvious? (wouldn't be the first time... :)Comment #27
cday119 commentedIn Drupal 5.0 form_render has changed to drupal_render
Comment #28
chlobe commentedsubscribing