1

I created a form in custom module,

Something like:

 $form['form00'] = array(
      '#type' => 'textfield',
      '#title' => 'dummy',
    );
$form['form01'] = array(
      '#type' => 'textfield',
      '#title' => 'dummy1',
    );

Questions are:

  1. How do I theme the form? like wrapping them into some div, giving a class or id, and setting CSS property (e.g. float: left), etc.?

  2. Can I control it from AJAX ? If yes,how?

  • You should read about render arrays and theme templates in drupal 8. – Eyal Jun 10 '16 at 7:12
2

Short story for or Q1: Wrap your form01 and form02 in a container: https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Render!Element!Container.php/class/Container/8.2.x

Then add your classes with the #attribute variable like here:

'#attributes' => array(
    'class' => 'myclass',
  )

For Q2: It's a long story, read this: Ajax API on Drupal

Regards,

Rainer

  • for Q1. how do i define the CSS? once i define the class (or ID) ? – AnD Jul 16 '16 at 14:36
  • Create a css file with your styles and add it to the asset library of your module. Or attach the asset just to that form with the #attached library syntax. – Rainer Feike Jul 19 '16 at 13:08

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.