0

I need a help with Contact Form 7 and additional settings.

I would like to add this script:

<script type="text/javascript" src="https://example.js?mid=0000&refer=example_name"></script>

to

on_sent_ok:

I tried to do it in many ways but it is not working.

Xan
  • 74,770
  • 16
  • 179
  • 206
interlaw
  • 67
  • 2
  • 8
  • `on_sent_ok` expects a string of executable JS code. So if you want to load an external script, go research/look up how insert a script element dynamically, f.e. here http://stackoverflow.com/questions/3857874/how-to-dynamically-insert-a-script-tag-via-jquery-after-page-load And remember, the JS code you assign to `on_sent_ok` must be a valid JS string, so careful with line breaks. – CBroe Oct 04 '16 at 13:08
  • Unfortunately, I don't know how I should do it. I tried to add script but it is not working. Someone can help me? :( – interlaw Oct 10 '16 at 07:57
  • In WP, you should have jQuery available, so using getScript should work, try something like `on_sent_ok: '$.getScript("https://example.js?mid=0000&refer=example_name")'` – CBroe Oct 10 '16 at 08:44
  • Yes! It's working! Thank you for help. Good of you! Thank you @CBroe :) – interlaw Oct 11 '16 at 16:36

1 Answers1

0

on_sent_ok expects a string of executable JS code.

So to load and execute an external script, you can use jQuery's getScript, like so:

on_sent_ok: '$.getScript("https://example.js?mid=0000&refer=example_name‌​")'
CBroe
  • 91,630
  • 14
  • 92
  • 150