Skip to content

Commit

Permalink
Merge pull request #654 from sul-dlss/recaptcha-timeout
Browse files Browse the repository at this point in the history
Execute reCAPTCHA on form submit
  • Loading branch information
corylown authored Jul 1, 2024
2 parents 65ad53d + b39fbe7 commit 69b1626
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 12 additions & 2 deletions app/components/top_bar_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<div data-feedback-target="container" id="feedback" class="collapse">
<div class="container mt-3">
<div class="row justify-content-center">
<%= form_with url: feedback_path, method: :post, class: 'col-md-8' do |f| %>
<%= form_with url: feedback_path, method: :post, class: 'col-md-8', html: { name: 'feedback_form' } do |f| %>
<%= f.hidden_field :reporting_from, value: request.original_url %>
<div class="alert alert-info" role="alert">
<%= t('feedbacks.reporting_from', url: request.original_url) %>
Expand All @@ -41,7 +41,17 @@
</div>
<div class="mb-3 row">
<div class="col-md-9 offset-md-3">
<%= recaptcha_v3(action: 'feedback', turbolinks: true) %>
<%= recaptcha_v3(action: 'feedback') %>
<script type="text/javascript">
document.forms.feedback_form.addEventListener('submit', async function(e) {
e.preventDefault();
const response = await window.executeRecaptchaForFeedbackAsync();
if (response) {
setInputWithRecaptchaResponseTokenForFeedback('g-recaptcha-response-data-feedback', response);
}
this.submit();
});
</script>
</div>
</div>
<div class="mb-3 row">
Expand Down
2 changes: 1 addition & 1 deletion spec/features/feedback_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
expect(page).to have_no_css('#feedback')

click_on 'Feedback'
expect(page).to have_css('#feedback form')
expect(page).to have_css('#feedback form[name="feedback_form"]')
end
end

0 comments on commit 69b1626

Please sign in to comment.