albertcht / invisible-recaptcha

An invisible reCAPTCHA package for Laravel, Lumen, CI or native PHP.
MIT License
603 stars 163 forks source link

(Re)Load @captcha directive in form via AJAX #102

Open elijahpaul opened 5 years ago

elijahpaul commented 5 years ago

Any idea how I'd go about using this package in a form that is loaded/refreshed via AJAX?

I'm currently refreshing an existing form in place via jQuery .load()?

register.blade.php

......
<div id="content">
    <form method="POST" action="{{ secure_url('register') }}">
        @csrf
        <input id="name" type="text" name="name" required autofocus>
        <input id="email" type="email" name="email" required>
        <input id="password" type="password" name="password" required>
        <button id="submit-btn" type="submit" class="btn">
        @captcha()
    </form>
</div>
......

AJAX that reloads the above form

......
$.ajax({  
  data: {locale: lang_prefix},  
  type: 'GET',  
  url: '/locale/' + lang_prefix,  
  success: function (result) {        
  $('#content ').load(location.href + ' #content>*', '');
  }  
});
......

but the scripts in the rendered @captcha directive don't reload/execute.