After Build use in Drupal


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function yourmodulename_form_alter(&$form, $form_state, $form_id) {
  2. if($form_id == 'thisformid'){
  3. $form['field']['#prefix'] = 'This text gets overwritten by the after build';
  4. $form['#after_build'][] = 'yourmodulename_after_build'; //Calls function
  5. //drupal_add_css('hello.css'); This line does not work when validation fails
  6. }
  7. }
  8.  
  9. function yourmodulename_after_build($form, &$form_state) {
  10. $form['field']['#prefix'] = 'This text will rule them all!';
  11. drupal_add_css('hello.css'); //This line works even after validation fails.
  12. return $form;
  13. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.