AI要約
説明
wpforms_process_complete アクションは、(成功した) フォームエントリ処理の最後に実行されます。
パラメーター
- $fields
- (array) サニタイズされたエントリーフィールドの値/プロパティ。
- $entry
- (array) 元の $_POST グローバル。
- $form_data
- (配列) 後で使用するために処理および準備されたフォーム設定/データ。
- $entry_id
- (int) エントリ ID。エントリの保存が無効になっている場合、または WPForms Lite を使用している場合は 0 を返します。
ソース
wpforms/includes/class-process.php
詳細情報
wpforms_process_complete フックは、フォーム処理の最後に実行されます。エントリが成功し、エラーが含まれていない場合にのみ実行されます。データベースへのエントリの保存とメール通知の送信は、このフックが実行される前に行われます。
カスタム API インテグレーションの構築や、エントリが正常に送信された後に何らかのアクションを実行する必要がある場合 (カスタムメール通知の送信、投稿やユーザーアカウントの作成など) に人気のある選択肢です。
フォーム ID で簡単に制限できるこのフックの代替バージョンとして、wpforms_process_complete_{$form_id} があります。
重要事項: 処理を実行し、エラーを返してフォーム処理を防止する必要がある場合は、代わりに wpforms_process フックを使用してください。
例
例については、Bill Erickson の「Integrating your contact form with external services」を参照してください。
対象とするフォーム ID に 5 を変更することを忘れないでください。
/**
* This will fire at the very end of a (successful) form entry.
*
* @link https://wpforms.com/developers/wpforms_process_complete/
*
* @param array $fields Sanitized entry field values/properties.
* @param array $entry Original $_POST global.
* @param array $form_data Form data and settings.
* @param int $entry_id Entry ID. Will return 0 if entry storage is disabled or using WPForms Lite.
*/
function wpf_dev_process_complete( $fields, $entry, $form_data, $entry_id ) {
// Optional, you can limit to specific forms. Below, we restrict output to
// form #5.
if ( absint( $form_data[ 'id' ] ) !== 5 ) {
return;
}
// Get the full entry object
$entry = wpforms()->entry->get( $entry_id );
// Fields are in JSON, so we decode to an array
$entry_fields = json_decode( $entry->fields, true );
// Check to see if user selected 'yes' for callback
if($entry_fields[6][ 'value' ] === 'Yes') {
// Set the hidden field to 'Needs Callback' to filter through entries
$entry_fields[7][ 'value' ] = 'Needs Callback';
}
// Convert back to json
$entry_fields = json_encode( $entry_fields );
// Save changes
wpforms()->entry->update( $entry_id, array( 'fields' => $entry_fields ), '', '', array( 'cap' => false ) );
}
add_action( 'wpforms_process_complete', 'wpf_dev_process_complete', 10, 4 );