By jan.koprowski on
Hi !
I add some extra fields to node using hook_form_alter() but also i need add some CSS to style them. So I have something like:
<?php function node_thumb_form_alter(&$form, $form_state, $form_id) {
drupal_add_css(drupal_get_path('module', 'node_thumb') .'/node_thumb.css');
?>and after i load my node page all is right but after i send the node form and some get some errors in fields (for example required field was empty) my node_thumb.css wasn't load. Why? What I'am doing wrong?
Comments
Hi jan, I think the problem
Hi jan,
I think the problem is that the form is loaded from cache when an error appears in submission, so that the hook_form_alter() is not invoked. I also had this problem when I wanted to alter a node form, and I solved it by putting the statement that adds the css in the hook_nodeapi, on the $op = 'prepare' (http://api.drupal.org/api/function/hook_nodeapi/6).
I hope to work also for you...
Vasi.
Thank You for greate response
Thank You for greate response :) I found very intresting discussion drupal_add_js in hook_form_alter where solution which seems to be ideal for me was add css using #build_after trigger :) I just add:
Working like a charm:)
Marking for reference.
Marking for reference.
Contact me to contract me for D7 -> D10/11 migrations.
Actually...
It's
$form['#after_build']not$form['#build_after']. So, this works perfectly :Thanks for the help!