AMP

Important: this documentation is not applicable to your currently selected format stories!

amp-recaptcha-input

Appends a reCAPTCHA v3 token to AMP form submissions.

Required Scripts

<script async custom-element="amp-recaptcha-input" src="https://cdn.ampproject.org/v0/amp-recaptcha-input-0.1.js"></script>

Supported Layouts

Behavior

This extension adds a parameter containing a recaptcha response token when a parent <form> element submits. amp-recaptcha-input does this by creating an iframe to load the reCAPTCHA v3 api script using the provided site key, and calling grecaptcha.execute with the provided site key and action.

Example

This example demonstrates how <amp-recaptcha-input> usage on an AMP page correlates to calls on the grecaptcha object and form body. <amp-recaptcha-input> must be a child of a <form> element.

<amp-recaptcha-input> usage

<form amp-form-attributes-go-here>
  ...
  <amp-recaptcha-input layout="nodisplay" name="reCAPTCHA_body_key" data-sitekey=”reCAPTCHA_site_key" data-action="reCAPTCHA_example_action">
  </amp-recaptcha-input>
  ...
</form>

Corresponding grecaptcha call

grecaptcha.execute('reCAPTCHA_site_key', {action: 'reCAPTCHA_example_action'});

Corresponding AMP form submit body

{
  ...other form params
  reCAPTCHA_body_key: returned_reCAPTCHA_response_token
}

Attributes

layout (required) Required value is nodisplay.
name (required) Name of the <amp-recaptcha-input>. Will be used as a parameter key in the AMP form body submission.
data-sitekey (required) reCAPTCHA v3 site key for the registered website.
data-action (required) reCAPTCHA v3 action to be executed on form submission.
data-global [optional] By default, the iframe loads the recaptcha api script using the www.google.com endpoint. There are some situations when this is not accessible. When the data-global attribute is included, the component will load the script from the www.recaptcha.net endpoint instead. More information can be found in the reCAPTCHA FAQ.

Validation

See <amp-recaptcha-input> rules in the AMP validator specification.

需要更多帮助?

您多次阅读的资料未能涵盖您的所有问题?也许其他人也这么觉得 在 Stack Overflow 上与他们取得联系。

前往 Stack Overflow
找到一个 bug 或者缺失某项功能?

AMP 项目强烈鼓励您参与其中并作出贡献!我们希望您能成为我们开源社区的持续参与者,但我们也欢迎您对热衷问题做出单次贡献。

前往 GitHub