cssformsvalidationdrupal-7form-api

Drupal 7 missing css rules after form validation failed


I am trying to validate my custom module form. The validation works like charm even if I use hook_validate or use the #validate attribute in the submit button. The problem is that after validation failed the form losses the css styles I have attached to the module. I am attaching the css on module using the .info file. I have also tried to re attache the css at the bottom of the validation function using drupal_add_css or the #attached attribute. If anyone had the same issue please let me know. I will appreciate any ideas or any help. Thanks.


Solution

  • If someone having the same problem I found the solution. After validation Drupal changes the html form id. If you are using css selectors based on the form id, just add a custom class name to your form using the #attributes form attribute somewhere in your form creating function.

    $form['#attributes'] = array('class' => array('your_id'));
    

    Then use this class for various selections in your css file.

    OR

    You can always use attribute CSS selectors with wildcards.