J
J
Jiffa2018-02-22 09:26:46
Drupal
Jiffa, 2018-02-22 09:26:46

How to make a form in a modal window on Drupal7?

The site has a feedback form that opens in a modal window via colorbox. The form has validation for 2 fields (mandatory name and phone number) and recaptcha from Google, added through the recaptcha module. The problem is this:
when the form opens, colorbox loads the page with the form and another colorbox script is connected, with each next opening of the form, these colorboxes begin to multiply at a terrible rate and only one of the new windows has captcha. In the colorbox module, I added the form pages to the exceptions and the problem with colorbox reproduction was solved, but now validation for any of the fields and captcha do not work. When submitting the form, the following error appears in the console:

colorbox_inline.js?p4jesu:18 Uncaught TypeError: $(...).once(...).colorbox is not a function
    at Object.attach (/sites/all/modules/colorbox/js/colorbox_inline.js?p4jesu:18:65)
    at Object.<anonymous> (<anonymous>:76:12)
    at Function.each (<anonymous>:33:533)
    at Object.Drupal.attachBehaviors (<anonymous>:74:5)
    at Object.insert (<anonymous>:570:14)
    at Drupal.ajax.success (<anonymous>:428:44)
    at Object.success (<anonymous>:189:19)
    at Object.a.success (<anonymous>:12:5494)
    at s (<anonymous>:12:2083)
    at window.(anonymous function) (<anonymous>:12:2947)

if you work with the form on a separate page, then there are no errors

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
Jiffa, 2018-02-22
@Jiffa

I solved the problem by opening the modal through the iframe. There is such an option in the colorbox module, or through the code

$('.selector').colorbox({
   iframe: true
})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question