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? Nov 11 '14 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? Nov 11 '14 at 9:13
  • Did you try adding "element-invisible" class to the form element? Why do you prefer adding only inline styles? Nov 11 '14 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. Nov 11 '14 at 9:41
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, privacy policy and cookie policy

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