I set up a custom form template using Sprout Forms and added
{{ craft.sproutInvisibleCaptcha.protect() }}
inside
the <form>
tag.
私はプラグインによっていくつかのcaptchaタグが追加されているのを見ることができますが、私はAJAXの投稿を使用しています:
- この提出方法を使用して動作させるにはどうすればよいですか?
- 「リダイレクト」の場所へのリダイレクトはどのように処理しますか?
私はこれらのテストを行った:
- ユーザーがJavaScriptを有効にしていない場合にフォームがサブミリングされないようにする
- すべてのフォームフィールドを自動入力するロボットによるフォームの送信をブロックする:
- フォームに記入するのに最低限の時間を要する;
これらのテストはすべて失敗し、スパムは検出されませんでした。
これはカスタムSproutフォームテンプレート内のキャプチャフィールドです:
{{ craft.sproutInvisibleCaptcha.protect() }}
<input type="hidden" name="redirectOnFailure" value="{{ craft.request.getUrl() }}">
これはJSスクリプト内のAJAXポストです:
var postUrl = 'sproutForms/entries/saveEntry',
formData = {
action: postUrl,
handle: 'test',
fields: {}
};
formData['fields[minPrice]'] = $scope.results.minPrice;
formData['fields[maxPrice]'] = $scope.results.maxPrice;
formData = $.param(formData);
$.ajax({
type : 'POST',
url : postUrl,
data : formData,
dataType : 'json',
encode : true
});
あなたのコードとコメントに基づいて、次のようなものが必要です:
<form id="someFormId">
<input type="hidden" name="action" value="sproutForms/entries/saveEntry">
<input type="hidden" name="handle" value="test">
<input type="hidden" name="redirectOnFailure" value="{{ craft.request.getUrl() }}">
<!---some more fields-->
<button type="button" id="sendRequest" value="send">
</form>
あなたのようなあなたのjavascript
$("#sendRequest").click(function(){
var formData = $("#someFormId").serialize();
//proceed with your ajax request
});
reason: The Plugin checks all your variables in your
$_POST
request. Depending on the keys in this array it
checks for spam. In your request you send none of those fields
-> the plugin validation does not trigger. You can check which
fields are injected with the {{
function and add
craft.sproutInvisibleCaptcha.protect() }}
them manually in your request as well but it’s easier to just
serialize the form. Maybe you have to play around with the action
url. I’m used to craft 3 since two months and it could be I messed
up the exact parameter in a serialize for craft2