0

The following are the code in my module function for textfield in my form:

 $form['price'] = array(
   '#type' => 'textfield',
   '#title' => 'What is Your Price?',
   '#size' => 100,
   '#maxlength' => 10,
   '#required' => TRUE,
  ); 

Now I want to add css for the textbox like I want to add inline code display:none; only for the textbox. How can I do that? Please help.

4
  • Can't you use the default classes generated by drupal? Commented Nov 11, 2014 at 8:52
  • I just want to add the inline css.I am not intending to add css class.Like in general I can write the following code <input type='text' name='abs' style='display:none;'>. But in Drupal How can I add the style part for the text box? Commented Nov 11, 2014 at 9:13
  • Did you try adding "element-invisible" class to the form element? Why do you prefer adding only inline styles? Commented Nov 11, 2014 at 9:17
  • I want to hide the textbox at first.Then if someone click on a button the textbox will show.thats why I want add a display:none for the textbox. Commented Nov 11, 2014 at 9:41

1 Answer 1

2

I do it like this:

function the_form($form, &$form_state){
     $form['price'] = array(
       '#type' => 'textfield',
       '#title' => 'What is Your Price?',
       '#size' => 100,
       '#maxlength' => 10,
       '#required' => TRUE,
       '#prefix' => '<div style="display:none;">',
       '#suffix' => '</div>',
     ); 
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.