Please Disable Your Browser Adblock Extension for our site and Refresh This Page!

our ads are user friendly, we do not serve popup ads. We serve responsible ads!

Refresh Page
Skip to main content
On . By CodimTh
Category:

How to show form in popup in Drupal 8 & 9

 

Example how to show a custom form in popup when user click a link from front end.

If you want to make a link modal, so that it will open in a popup, you have to set the class use-ajax and the attribute data-dialog-type like in this example:

$content['add_movie'] = array(
     '#type' => 'link',
     '#title' => $this->t('Add movie'),
     '#url' => Url::fromRoute('node.add', ['node_type' => 'content_type_movie']),
     '#attributes' => [
       'class' => ['use-ajax'],
       'data-dialog-type' => 'modal',
       'data-dialog-options' => Json::encode([
         'width' => 700,
       ]),
     ],
   );

 

I Hope this tips helps you.

Comments

Add new comment

Restricted HTML

Search

Page Facebook

Become a patron

If you need some help or you search a Drupal freelancer don't hesitate to contact us.

 

Contact Us

All the content is FREE but I still need your help

 

Become a patreon