php Gravity Perks // GF嵌套表单//自动附加文件上传到父表单通知
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php Gravity Perks // GF嵌套表单//自动附加文件上传到父表单通知相关的知识,希望对你有一定的参考价值。
<?php
/**
* Gravity Perks // GF Nested Forms // Auto-attach File Uploads to Parent Form Notifications
* http://gravitywiz.com/documentation/gravity-forms-nested-forms/
*/
add_filter( 'gform_notification', function( $notification, $form, $entry ) {
if( ! is_callable( 'gp_nested_forms' ) ) {
return $notification;
}
$nested_form_fields = GFCommon::get_fields_by_type( $form, array( 'form' ) );
if( empty( $nested_form_fields ) ) {
return $notification;
}
$parent_entry = new GPNF_Entry( $entry );
$attachments = array();
foreach( $nested_form_fields as $nested_form_field ) {
$child_entries = $parent_entry->get_child_entries( $nested_form_field->id );
if( empty( $child_entries ) ) {
continue;
}
$child_form = GFAPI::get_form( $nested_form_field->gpnfForm );
$upload_fields = GFCommon::get_fields_by_type( $child_form, array( 'fileupload' ) );
$upload_root = GFFormsModel::get_upload_root();
foreach( $child_entries as $child_entry ) {
foreach ( $upload_fields as $upload_field ) {
// Get field value.
$attachment_urls = rgar( $child_entry, $upload_field->id );
// If field value is empty, skip.
if ( empty( $attachment_urls ) ) {
continue;
}
// Convert to array.
$attachment_urls = $upload_field->multipleFiles ? json_decode( stripslashes( $attachment_urls ), true ) : array( $attachment_urls );
// Loop through attachment URLs; replace URL with path and add to attachments.
foreach ( $attachment_urls as $attachment_url ) {
$attachment_url = preg_replace( '|^(.*?)/gravity_forms/|', $upload_root, $attachment_url );
$attachments[] = $attachment_url;
}
}
}
$notification['attachments'] = array_merge( rgar( $notification, 'attachments', array() ), $attachments );
return $notification;
}
}, 10, 3 );
以上是关于php Gravity Perks // GF嵌套表单//自动附加文件上传到父表单通知的主要内容,如果未能解决你的问题,请参考以下文章
php Gravity Perks //嵌套表单//保存并继续清除会话Cookie
php Gravity Perks // GP嵌套表单//从值隐藏产品名称
php Gravity Perks //嵌套表单//每小时Cron和孤立条目到期
php Gravity Perks //嵌套表单//在父表单提交上复制父条目属性
php Gravity Perks //嵌套表单//在提交时强制{Parent}合并标记替换
php Gravity Perks // GP嵌套表单//更改子表单的提交按钮文本