[themes] how to theme [class/id] a nord_form?

Christopher M. Jones cjones at partialflow.com
Wed Nov 11 20:07:33 UTC 2009


What you could do is create overrides for each form element type, adding 
an id or class based on the name or some other attribute of the form 
element. I've done this to style specific form elements in forms. That 
might be simpler than unsetting properties in the form array, and you 
could do it all from within your template rather than having to create a 
whole module. Have a look at the theme functions in the API 
documentation to see how you can do this.

sebastian wrote:
> Hi Thanks Lee, others,
> 
> My ideal solution would be if the form elements had id or class names, 
> that were unique, so that I could simply hide [display:none] the form 
> elements that I don't feel like the less-tech savvy content admins need 
> to see.
> 
> My back-up solution was turning them off as a function, as part of the 
> drupal_render function.
> 
> This is for the node creation, of several node types; but right now I am 
> just trying the basic: node->create->page type.
> 
> Couple of questions:
> 
> 1. is there a way to inject class and/or node ID's to the basic 
> node_edit form? I would want the title to always have something like 
> "id="node_title" on ALL of my node edit forms; whether it is for adding 
> a 'page' type, or a new type not yet imagined but latter added. [that 
> way if I am always hiding the 'publishing options' section, for a 
> particular user, it would be hidden site-wide on all forms]
> 
> 2. if it is NOT possible to do the above, then my backup is to use 
> drupal_render(), as described below. Am I correct that I would just use:
> 
> unset($form['name_of_element']);
> drupal_render($form);
> 
> ?
> 
> 3. If there is anyway I could take my work [above] and make it into a 
> module for others to benefit from this change, I would love to 
> contribute this to the drupal community. As I think I must not be the 
> only person who wants to style specific elements on the node-creation 
> page, and right now there is simply no way to target these fields in CSS...
> 
> I've never contributed before though, and still learning, so not sure if 
> whatever changes I make will be compatible as a "module"
> 
> Thank you so much for your help!!
> 
> Sebastian.
> 
> Lee Rowlands wrote:
>>> When I have a nord_form, either for creation or editing, I get a lot of 
>>> id's like: #thmr_81, thmr_86, #thmr_91, #thmr_98
>> These are inserted by the devel_themer module and should not be relied upon
>>
>>> But if I replace $output .= drupal_render($form); with
>>>
>>> $output .= drupal_render($form['title']);
>>> $output .= drupal_render($form['body_field']);
>>> $output .= drupal_render($form['custom_select_field']);
>>>
>>> Which are the only three I actually need to have displayed for a 
>>> non-admin, then the page will NOT save, [no errors, it just reloads the 
>>> page and erases all my changes]
>> The call to drupal_render($form) actually renders the hidden elements such
>> as form id and build id which are needed to determine if the form was
>> submitted by the Form API. If these aren't found, the Form API thinks it
>> wasn't submitted and hence no submit function is called and no data is
>> saved.
>> You need to examine the $form variable and unset (using the unset function)
>> any array members (form elements) you don't want then add a final
>> drupal_render($form) to the end of your output and thiss will add all the
>> hidden stuff (and anything else that still yet to be rendered).
>> I'm assuming you don't have a module here? Otherwise you could do the
>> unsetting in hook_form_alter.
>>
>> _______________________________________________
>> themes mailing list
>> themes at drupal.org
>> http://lists.drupal.org/mailman/listinfo/themes
>>
> _______________________________________________
> themes mailing list
> themes at drupal.org
> http://lists.drupal.org/mailman/listinfo/themes
> 


More information about the themes mailing list