Awesome
KMS Feedback
This extension allows submitting contact/callback/feedback forms from frontend side and having it under "Messages" section in KMS. When ActionMailer settings setup, it notifies selected users about new messages by email as well.
Installation
-
Add to Gemfile:
gem "kms_feedback" # or for edge version: gem "kms_feedback", github: "webgradus/kms_feedback"
-
Run generator:
rails g kms_feedback:install
-
Copy migrations:
rails kms_feedback:install:migrations
-
Migrate:
rails db:migrate
-
Recompile assets:
rails assets:precompile
-
Restart KMS instance
Usage
Your form on webpage should look like this:
<form action="/feedbacks" method="post">
<input type="hidden" name='authenticity_token' value='{{ request.form_authenticity_token }}'>
<input type="text" name="feedback[name]" placeholder="Name">
<input type="tel" name="feedback[phone]" placeholder="Phone">
<input type="email" name="feedback[email]" placeholder="Email">
<textarea name="feedback[message]" placeholder="Message"></textarea>
<input type="submit">
</form>
IMPORTANT!
Necessary to have form's action and method exactly like above (as well as inputs names).
And don't forget about authenticity_token
.
Form validation should happen completely on client side (you could use HTML5 attrs or parsley.js or something similar).
You can use only some of fields - only name
and phone
for example.
To make AJAX submit you would have something like this JavaScript code:
<script>
$(document).ready(function(){
$('input[type="button"]').click(function(){
$.post('/feedbacks', $('form[action="/feedbacks"]').serialize());
});
});
</script>
and add validation as well.
This extension also provides adding Recaptcha to forms. For adding validation with Recaptcha:
-
Insert this fragment before closing </head> in your HTML:
<script src='https://www.google.com/recaptcha/api.js'></script>
-
Insert this fragment at the bottom of <form> contents (where you need to place reCAPTCHA widget):
<div class="g-recaptcha" data-sitekey="RECAPTCHA_PUBLIC_KEY"></div>
-
Enable Recaptcha under "Settings" (check dropdown menu on avatar clicking)
Another way to prevent spam is to enable Invisible Captcha (check out Settings in your KMS admin section). For adding validation with InvisibleCaptcha:
-
Insert this fragment into your feedback form:
<div style="display:none;"> <input type="text" name="feedback[captcha]" placeholder="Don't fill this if you're human"> </div>
-
Enable Invisible Captcha under "Settings" (check dropdown menu on avatar clicking)
This project rocks and uses MIT-LICENSE.