From e18c6ec9e6d514d641864a7f6347d9660f7d994c Mon Sep 17 00:00:00 2001 From: Teon Ooi Date: Thu, 19 Dec 2024 13:49:24 +0800 Subject: [PATCH 1/2] [twgit] Init feature 'feature-PRESIDECMS-2964_recording-where-a-formbuilder-form-has-been-submitted-from'. From 080148db0a23bde9e1e0fae061e38f3959cdacd4 Mon Sep 17 00:00:00 2001 From: Teon Ooi Date: Thu, 19 Dec 2024 13:54:38 +0800 Subject: [PATCH 2/2] PRESIDECMS-2964 Update to record submission from. --- system/handlers/formbuilder/Core.cfc | 8 +++--- .../content/FormBuilderSubmissionFormUrl.cfc | 26 +++++++++++++++++++ system/handlers/widgets/FormBuilderForm.cfc | 3 +++ .../formbuilder_formsubmission.properties | 2 ++ .../formbuilder_formsubmission.cfc | 12 ++++++--- .../formbuilder/FormBuilderService.cfc | 24 +++++++++++------ .../admin/formbuilder/viewSubmission.cfm | 3 +++ 7 files changed, 63 insertions(+), 15 deletions(-) create mode 100644 system/handlers/renderers/content/FormBuilderSubmissionFormUrl.cfc diff --git a/system/handlers/formbuilder/Core.cfc b/system/handlers/formbuilder/Core.cfc index a8a4254c8a..1292ed91e9 100644 --- a/system/handlers/formbuilder/Core.cfc +++ b/system/handlers/formbuilder/Core.cfc @@ -47,9 +47,11 @@ component { } var validationResult = formBuilderService.saveFormSubmission( - formId = formId - , requestData = submission - , instanceId = ( rc.instanceId ?: "" ) + formId = formId + , requestData = submission + , instanceId = ( rc.instanceId ?: "" ) + , instanceSite = ( rc.instanceSite ?: "" ) + , instanceUrl = ( rc.instanceUrl ?: "" ) ); if ( event.isAjax() ) { diff --git a/system/handlers/renderers/content/FormBuilderSubmissionFormUrl.cfc b/system/handlers/renderers/content/FormBuilderSubmissionFormUrl.cfc new file mode 100644 index 0000000000..2faf5b13a2 --- /dev/null +++ b/system/handlers/renderers/content/FormBuilderSubmissionFormUrl.cfc @@ -0,0 +1,26 @@ +/** + * @feature formbuilder + */ +component { + + property name="formBuilderService" inject="SiteService"; + property name="formBuilderService" inject="FormBuilderService"; + + private string function default( event, rc, prc, args={} ) { + if ( !isEmptyString( args.data ?: "" ) ) { + var submissionId = ( rc.submissionId ?: ( args.record.id ?: ( rc.id ?: "" ) ) ); + + var submission = formBuilderService.getSubmission( submissionId ); + + if ( !isEmptyString( submission.form_site ?: "" ) ) { + + var link = event.getSiteUrl( submission.form_site ) & args.data; + + return '#link#'; + } + } + + return ""; + } + +} \ No newline at end of file diff --git a/system/handlers/widgets/FormBuilderForm.cfc b/system/handlers/widgets/FormBuilderForm.cfc index 51724f67de..324ab5467c 100644 --- a/system/handlers/widgets/FormBuilderForm.cfc +++ b/system/handlers/widgets/FormBuilderForm.cfc @@ -64,6 +64,9 @@ component { rendered &= '

' & translateResource( "formbuilder:#resubmitMessage#") & '

'; } + args.instanceSite = args.instanceSite ?: event.getSiteId(); + args.instanceUrl = args.instanceUrl ?: event.getCurrentUrl(); + rendered &= formbuilderService.renderForm( formId = formId , layout = layout diff --git a/system/i18n/preside-objects/formbuilder_formsubmission.properties b/system/i18n/preside-objects/formbuilder_formsubmission.properties index 267cc12c7b..1efad0e6b4 100644 --- a/system/i18n/preside-objects/formbuilder_formsubmission.properties +++ b/system/i18n/preside-objects/formbuilder_formsubmission.properties @@ -5,5 +5,7 @@ field.submitted_by.title=Submitted by field.datecreated.title=Submitted on field.submitted_data.title=Response field.form_instance.title=Form instance +field.form_site.title=Form site +field.form_url.title=Form url field.ip_address.title=IP Address field.user_agent.title=User agent \ No newline at end of file diff --git a/system/preside-objects/formbuilder/formbuilder_formsubmission.cfc b/system/preside-objects/formbuilder/formbuilder_formsubmission.cfc index c10c65800f..768f70c919 100644 --- a/system/preside-objects/formbuilder/formbuilder_formsubmission.cfc +++ b/system/preside-objects/formbuilder/formbuilder_formsubmission.cfc @@ -9,8 +9,12 @@ component displayname="Form builder: form" extends="preside.system.base.SystemPr property name="form" relationship="many-to-one" relatedto="formbuilder_form" required=true; property name="submitted_by" relationship="many-to-one" relatedTo="website_user" required=false renderer="websiteUser" ondelete="set-null-if-no-cycle-check" onupdate="cascade-if-no-cycle-check" feature="websiteUsers"; - property name="submitted_data" type="string" dbtype="text" required=false renderer="formbuilderSubmission"; - property name="form_instance" type="string" dbtype="varchar" maxlength=200 required=false; - property name="ip_address" type="string" dbtype="varchar" maxlength=50 required=false; - property name="user_agent" type="string" dbtype="text" required=false; + property name="submitted_data" type="string" dbtype="text" required=false renderer="formbuilderSubmission"; + + property name="form_instance" type="string" dbtype="varchar" maxlength=200 required=false; + property name="form_url" type="string" dbtype="text" required=false renderer="formbuilderSubmissionFormUrl"; + property name="form_site" relationship="many-to-one" relatedTo="site" required=false; + + property name="ip_address" type="string" dbtype="varchar" maxlength=50 required=false; + property name="user_agent" type="string" dbtype="text" required=false; } \ No newline at end of file diff --git a/system/services/formbuilder/FormBuilderService.cfc b/system/services/formbuilder/FormBuilderService.cfc index 65693b6cba..9e249d0aae 100644 --- a/system/services/formbuilder/FormBuilderService.cfc +++ b/system/services/formbuilder/FormBuilderService.cfc @@ -1023,9 +1023,11 @@ component { public any function saveFormSubmission( required string formId , required struct requestData - , string instanceId = "" - , string ipAddress = Trim( ListLast( cgi.remote_addr ?: "" ) ) - , string userAgent = ( cgi.http_user_agent ?: "" ) + , string instanceId = "" + , string instanceSite = "" + , string instanceUrl = "" + , string ipAddress = Trim( ListLast( cgi.remote_addr ?: "" ) ) + , string userAgent = ( cgi.http_user_agent ?: "" ) ) { setFormBuilderSubmissionContextData( arguments.formId, arguments.requestData ); @@ -1056,20 +1058,26 @@ component { if ( validationResult.validated() ) { if ( isV2Form( arguments.formid ) ) { submissionId = $getPresideObject( "formbuilder_formsubmission" ).insertData( data={ - form = arguments.formId - , submitted_by = $getWebsiteLoggedInUserId() - , form_instance = arguments.instanceId - , ip_address = arguments.ipAddress - , user_agent = arguments.userAgent + form = arguments.formId + , submitted_by = $getWebsiteLoggedInUserId() + , form_instance = arguments.instanceId + , form_site = arguments.instanceSite + , form_url = arguments.instanceUrl + , ip_address = arguments.ipAddress + , user_agent = arguments.userAgent } ); + saveV2Responses( formId=arguments.formId, formData=formData, formItems=formItems, submissionId=submissionId ); } else { formData = renderResponsesForSaving( formId=arguments.formId, formData=formData, formItems=formItems ); + submissionId = $getPresideObject( "formbuilder_formsubmission" ).insertData( data={ form = arguments.formId , submitted_by = $getWebsiteLoggedInUserId() , submitted_data = SerializeJson( formData ) , form_instance = arguments.instanceId + , form_site = arguments.instanceSite + , form_url = arguments.instanceUrl , ip_address = arguments.ipAddress , user_agent = arguments.userAgent } ); diff --git a/system/views/admin/formbuilder/viewSubmission.cfm b/system/views/admin/formbuilder/viewSubmission.cfm index acea9da262..d2a849d929 100644 --- a/system/views/admin/formbuilder/viewSubmission.cfm +++ b/system/views/admin/formbuilder/viewSubmission.cfm @@ -18,6 +18,9 @@
#translateResource( "preside-objects.formbuilder_formsubmission:field.form_instance.title")#
#renderField( 'formbuilder_formsubmission', 'form_instance', prc.submission.form_instance )#
+
#translateResource( "preside-objects.formbuilder_formsubmission:field.form_url.title")#
+
#renderField( 'formbuilder_formsubmission', 'form_url', prc.submission.form_url )#
+
#translateResource( "preside-objects.formbuilder_formsubmission:field.ip_address.title")#
#renderField( 'formbuilder_formsubmission', 'ip_address', prc.submission.ip_address )#