---
title: "ウォークスルー:カスタム送信アクションの作成"
slug: "walkthrough--creating-a-custom-submit-action"
abstract: "フォームの送信状況に関するエントリをログファイルに追加する送信アクションを作成します。"
---
# ウォークスルー:カスタム送信アクションの作成

ナビゲーションには「送信」ボタン(前→次→ボタン)を使い、フォームの提出や送信アクションのトリガーを行います。すべての送信ボタンに異なる種類のアクションを追加できます。例えば、「送信アクション「次のボタンに追加された**データを保存**」は、連絡先が「**次へ**」をクリックしてフォームの次のページに進んだ際にフォーム[データベース](https://doc.sitecore.com/xp/en/developers/104/platform-administration-and-architecture/en/forms-database.html)に保存されます。デフォルトでは、トリガー目標、トリガーキャンペーン活動、トリガーアウトカム、ページへのリダイレクト、データ送信項目を追加できます。

このウォークスルーでは、フォームの送信状況に関するエントリをログファイルに追加するカスタム送信アクションの作成方法を説明します。以下の方法を説明しています:

-   サブミッション・アクションクラスを作成する
-   アクションアイテムを提出する

## サブミッション・アクションクラスを作成する

カスタム送信アクションを作成する際は、SubmitActionBase<TParametersData> クラスから継承するクラスを作成しなければなりません。

サブミットアクションクラスを作成するには:

1.  LogSubmitクラスを作成し、SubmitActionBase<TParametersData>
    
2.  TParametersDataの種類を指定してください。
    
3.  TryParse メソッドをオーバーライドして、空の文字列パラメータを解析し、trueを返します。
    
4.  Executeメソッドを上書きし、フォーム送信状況とフォームIDを含むメッセージをログに残します。例えば:
    
    using System.Linq;
    using Sitecore.Diagnostics;
    using Sitecore.ExperienceForms.Models;
    using Sitecore.ExperienceForms.Processing;
    using Sitecore.ExperienceForms.Processing.Actions;
    using static System.FormattableString;
    
    namespace Sitecore.ExperienceForms.Samples.SubmitActions
    {
     /// <summary>
     /// Executes a submit action for logging the form submit status.
     /// </summary>
     /// <seealso cref="Sitecore.ExperienceForms.Processing.Actions.SubmitActionBase{TParametersData}" />
     public class LogSubmit : SubmitActionBase<string>
     {
     /// <summary>
     /// Initializes a new instance of the <see cref="LogSubmit"/> class.
     /// </summary>
     /// <param name="submitActionData">The submit action data.</param>
     public LogSubmit(ISubmitActionData submitActionData) : base(submitActionData)
     {
     }
    
     /// <summary>
     /// Tries to convert the specified <paramref name="value" /> to an instance of the specified target type.
     /// </summary>
     /// <param name="value">The value.</param>
     /// <param name="target">The target object.</param>
     /// <returns>
     /// true if <paramref name="value" /> was converted successfully; otherwise, false.
     /// </returns>
     protected override bool TryParse(string value, out string target)
     {
     target = string.Empty;
     return true;
     }
    
     /// <summary>
     /// Executes the action with the specified <paramref name="data" />.
     /// </summary>
     /// <param name="data">The data.</param>
     /// <param name="formSubmitContext">The form submit context.</param>
     /// <returns>
     /// <c>true</c> if the action is executed correctly; otherwise <c>false</c>
     /// </returns>
     protected override bool Execute(string data, FormSubmitContext formSubmitContext)
     {
     Assert.ArgumentNotNull(formSubmitContext, nameof(formSubmitContext));
    
     if (!formSubmitContext.HasErrors)
     {
     Logger.Info(Invariant($"Form {formSubmitContext.FormId} submitted successfully."), this);
     }
     else
     {
     Logger.Warn(Invariant($"Form {formSubmitContext.FormId} submitted with errors: {string.Join(", ", formSubmitContext.Errors.Select(t => t.ErrorMessage))}."), this);
     }
    
     return true;
     }
     }
    }
    
5.  ビルドと展開
    

## アクションアイテムを提出する

アクションアイテムを提出するには:

1.  /sitecore/System/Settings/Formsに行って。
    
2.  右クリックで **「アクションを送信**」をクリックし、「 **挿入**」をクリックし、「 **テンプレートから挿入**」をクリックします。
    
3.  */System/Forms/Submit Action*テンプレートを選択し、**アイテム名**欄で名前*Log Submit*を入力し、「**挿入**」をクリックします。
    
    ![Insert from Template dialog](https://doc.sitecore.com/api/markdown-image/xp/ja/developers/92/sitecore-experience-manager/images/FORMS-insert-from-template.png)
    
4.  作成したアイテムにアクセスし、**設定** セクションの**Model Type**フィールドで、クラスタイプ名に値を設定します。
    
5.  **エラーメッセージ**フィールドにエラーメッセージを入力してください。例えば「*ログ送信失敗!」*などです。
    
6.  **Appearance**セクションで、Forms要素ペインで表示したいアイコンを選択します。
    

フォーム要素ペインで「送信を追加」アクションをクリックすると、「ログ送信」アクションを選択できます:

![Select the action](https://doc.sitecore.com/api/markdown-image/xp/ja/developers/92/sitecore-experience-manager/images/FORMS-log-submit.png)