バージョン | 記事リンク |
---|---|
AEM as a Cloud Service | この記事 |
AEM 6.5 | ここをクリックしてください |
AEM の外側にホストされた Web ページか AEM Sites ページに、アダプティブフォームをシームレスに埋め込むことができます。埋め込まれたアダプティブフォームではすべての機能を使用できるので、ユーザーは、ページから移動することなくフォームを記入および送信できます。これにより、ユーザーは web ページの他の要素から離れることなく、同時にフォームの操作も行うことができます。
アダプティブフォームを外部 Web サイトに埋め込む前に実行する手順
Web ページに数行の JavaScript を挿入することで、アダプティブフォームを埋め込むことができます。コードの API は AEM サーバーにアダプティブフォームのリソースを求める HTTP リクエストを送信し、指定したフォームコンテナにアダプティブフォームを挿入します。
アダプティブフォームを埋め込むには、以下のようにします。
次のコードを使用して、web サイト上に web ページを作成します。
<!doctype html>
<html>
<head>
<title>This is the title of the webpage!</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<div class="customafsection"/>
<p>This section is replaced with the adaptive form.</p>
<script>
var options = {path:"/content/forms/af/myadaptiveform.html", CSS_Selector:".customafsection"};
alert(options.path);
var loadAdaptiveForm = function(options){
//alert(options.path);
if(options.path) {
// options.path refers to the path of the adaptive form
// For Example: /content/forms/af/ABC, where ABC is the adaptive form
// Note: If AEM server is running on a context path, the adaptive form URL must contain the context path
var path = options.path;
$.ajax({
url : path ,
type : "GET",
data : {
// wcmmode=disabled is only required for author instance
// wcmmode : "disabled"
},
async: false,
success: function (data) {
// If jquery is loaded, set the inner html of the container
// If jquery is not loaded, use APIs provided by document to set the inner HTML but these APIs would not evaluate the script tag in HTML as per the HTML5 spec
// For example: document.getElementById().innerHTML
if(window.$ && options.CSS_Selector){
// HTML API of jquery extracts the tags, updates the DOM, and evaluates the code embedded in the script tag.
$(options.CSS_Selector).html(data);
}
},
error: function (data) {
// any error handler
}
});
} else {
if (typeof(console) !== "undefined") {
console.log("Path of Adaptive Form not specified to loadAdaptiveForm");
}
}
}(options);
</script>
</body>
</html>
埋め込まれたコードで、
アダプティブフォームが Web ページに埋め込まれます。埋め込まれたアダプティブフォームで、以下の点を確認します。
アダプティブフォームを埋め込んだ外部 Web ページは、AEM サーバーにリクエストを送信します。このサーバーは通常、プライベートネットワークのファイアウォールの内側に配置されます。リクエストが AEM サーバーに安全に送信されるようにするには、リバースプロキシサーバーを設定することをお勧めします。
Dispatcher を使用せずに、Apache 2.4 リバースプロキシサーバーを設定する方法の例を見てみましょう。この例では、AEM サーバーを /forms
コンテキストパスでホストし、リバースプロキシの /forms
をマッピングします。これで、Apache サーバーの /forms
へのすべてのリクエストは、AEM インスタンスにダイレクトされます。このトポロジにより、前に /forms
の付いたすべてのリクエストが AEM サーバー経由になるため、ディスパッチャーレイヤーのルールの数を低減することができます。
httpd.conf
設定ファイルを開き、次のコードの行をコメント解除します。または、これらのコードの行をファイルに追加することができます。
LoadModule proxy_html_module modules/mod_proxy_html.so
LoadModule proxy_http_module modules/mod_proxy_http.so
次のコードの行を httpd-proxy.conf
設定ファイルに追加して、プロキシルールをセットアップします。
ProxyPass /forms https://[AEM_Instance]/forms
ProxyPassReverse /forms https://[AEM_Instance]/forms
[AEM_Instance]
を、ルールの AEM サーバー公開 URL で置き換えます。
コンテキストパスに AEM サーバーをマウントしない場合、Apache レイヤーのプロキシルールは次のようになります。
ProxyPass /content https://<AEM_Instance>/content
ProxyPass /etc https://<AEM_Instance>/etc
ProxyPass /etc.clientlibs https://<AEM_Instance>/etc.clientlibs
# CSRF Filter
ProxyPass /libs/granite/csrf/token.json https://<AEM_Instance>/libs/granite/csrf/token.json
ProxyPassReverse /etc https://<AEM_Instance>/etc
ProxyPassReverse /etc.clientlibs https://<AEM_Instance>/etc.clientlibs
# written for thank you page and other URL present in AF during redirect
ProxyPassReverse /content https://<AEM_Instance>/content
その他のトポロジーをセットアップする場合は、ディスパッチャーレイヤーの送信、事前入力、およびその他の URL を必ず許可リストに登録してください。
Web ページにアダプティブフォームを埋め込む際は、次のベストプラクティスを考慮してください。
[getData](https://developer.adobe.com/experience-manager/reference-materials/6-5/forms/javascript-api/GuideBridge.html)
API を使用して、クライアントのフォームデータの XML または JSON 表現を取得してください。[unloadAdaptiveForm](https://developer.adobe.com/experience-manager/reference-materials/6-5/forms/javascript-api/GuideBridge.html)
API を使用して、HTML DOM からアダプティブフォームをアンロードします。https://'[server]:[port]'/system/console/configMgr
)に移動します。