Skip to content

Commit

Permalink
Merge branch 'feature-PRESIDECMS-2964_recording-where-a-formbuilder-f…
Browse files Browse the repository at this point in the history
…orm-has-been-submitted-from' into release-10.28.0
  • Loading branch information
teonator committed Dec 20, 2024
2 parents 91e07ea + 080148d commit 5eee010
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 15 deletions.
8 changes: 5 additions & 3 deletions system/handlers/formbuilder/Core.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -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() ) {
Expand Down
26 changes: 26 additions & 0 deletions system/handlers/renderers/content/FormBuilderSubmissionFormUrl.cfc
Original file line number Diff line number Diff line change
@@ -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 '<a href="#link#">#link#</a>';
}
}

return "";
}

}
3 changes: 3 additions & 0 deletions system/handlers/widgets/FormBuilderForm.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ component {
rendered &= '<div class="alert alert-info"><p>' & translateResource( "formbuilder:#resubmitMessage#") & '</p></div>';
}

args.instanceSite = args.instanceSite ?: event.getSiteId();
args.instanceUrl = args.instanceUrl ?: event.getCurrentUrl();

rendered &= formbuilderService.renderForm(
formId = formId
, layout = layout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
24 changes: 16 additions & 8 deletions system/services/formbuilder/FormBuilderService.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down Expand Up @@ -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
} );
Expand Down
3 changes: 3 additions & 0 deletions system/views/admin/formbuilder/viewSubmission.cfm
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
<dt>#translateResource( "preside-objects.formbuilder_formsubmission:field.form_instance.title")#</dt>
<dd>#renderField( 'formbuilder_formsubmission', 'form_instance', prc.submission.form_instance )#</dd>

<dt>#translateResource( "preside-objects.formbuilder_formsubmission:field.form_url.title")#</dt>
<dd>#renderField( 'formbuilder_formsubmission', 'form_url', prc.submission.form_url )#</dd>

<dt>#translateResource( "preside-objects.formbuilder_formsubmission:field.ip_address.title")#</dt>
<dd>#renderField( 'formbuilder_formsubmission', 'ip_address', prc.submission.ip_address )#</dd>

Expand Down

0 comments on commit 5eee010

Please sign in to comment.