Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
Wpct ERP Forms
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
codeccoop
WordPress
plugins
Wpct ERP Forms
Commits
403d6284
Commit
403d6284
authored
1 year ago
by
Lucas García
Browse files
Options
Downloads
Patches
Plain Diff
feat: parse fileupload fields
parent
9d3bccd4
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
includes/submissions.php
+32
-12
32 additions, 12 deletions
includes/submissions.php
with
32 additions
and
12 deletions
includes/submissions.php
+
32
−
12
View file @
403d6284
...
...
@@ -12,7 +12,12 @@ function wpct_crm_forms_parse_form_entry($entry, $form)
foreach
(
$form
[
'fields'
]
as
$field
)
{
if
(
$field
->
type
===
'consent'
)
continue
;
$input_name
=
$field
->
inputName
?
$field
->
inputName
:
$field
->
label
;
$input_name
=
$field
->
inputName
?
$field
->
inputName
:
(
$field
->
adminLabel
?
$field
->
adminLabel
:
$field
->
label
);
$inputs
=
$field
->
get_entry_inputs
();
if
(
is_array
(
$inputs
))
{
// composed fields
...
...
@@ -31,7 +36,7 @@ function wpct_crm_forms_parse_form_entry($entry, $form)
foreach
(
$inputs
as
$input
)
{
$value
=
rgar
(
$entry
,
(
string
)
$input
[
'id'
]);
if
(
$input_name
&&
$value
)
{
$values
[]
=
$value
;
$values
[]
=
wpct_crm_forms_format_value
(
$value
,
$field
,
$input
)
;
}
}
...
...
@@ -40,7 +45,8 @@ function wpct_crm_forms_parse_form_entry($entry, $form)
}
else
{
// simple fields
if
(
$input_name
)
{
$form_vals
[
$input_name
]
=
rgar
(
$entry
,
(
string
)
$field
->
id
);
$raw_value
=
rgar
(
$entry
,
(
string
)
$field
->
id
);
$form_vals
[
$input_name
]
=
wpct_crm_forms_format_value
(
$raw_value
,
$field
);
}
}
}
...
...
@@ -48,6 +54,15 @@ function wpct_crm_forms_parse_form_entry($entry, $form)
return
$form_vals
;
}
function
wpct_crm_forms_format_value
(
$value
,
$field
,
$input
=
null
)
{
if
(
$field
->
type
===
'fileupload'
)
{
if
(
!
is_array
(
$field
->
get_entry_inputs
()))
return
json_decode
(
$value
)[
0
];
}
return
$value
;
}
function
wpct_crm_forms_add_cord_id
(
$form_values
)
{
if
(
!
isset
(
$form_values
[
'company_id'
])
||
!
$form_values
[
'company_id'
])
{
...
...
@@ -104,6 +119,7 @@ function wpct_crm_forms_get_submission_payload($form_vals)
/**
* Pipe form submission transformations to get the submission post payload
*/
add_filter
(
'wpct_crm_forms_prepare_submission'
,
'wpct_crm_forms_prepare_submission'
,
10
,
2
);
function
wpct_crm_forms_prepare_submission
(
$form_vals
)
{
$form_vals
=
wpct_crm_forms_add_cord_id
(
$form_vals
);
...
...
@@ -111,22 +127,26 @@ function wpct_crm_forms_prepare_submission($form_vals)
return
wpct_crm_forms_get_submission_payload
(
$form_vals
);
}
add_filter
(
'wpct_crm_forms_prepare_submission'
,
'wpct_crm_forms_prepare_submission'
,
10
,
2
);
/**
* Store uploads on a custom folder
*/
add_filter
(
'gform_upload_path'
,
'wpct_forms_
sm_
upload_path'
,
90
);
function
wpct_forms_
sm_
upload_path
()
add_filter
(
'gform_upload_path'
,
'wpct_
crm_
forms_upload_path'
,
90
);
function
wpct_
crm_
forms_upload_path
(
$path_info
)
{
$upload_dir
=
wp_upload_dir
();
$path
=
$upload_dir
[
'basedir'
]
.
'/forms'
;
if
(
!
is_dir
(
$path
))
mkdir
(
$path
);
$basedir
=
dirname
(
$upload_dir
[
'basedir'
]);
$path
=
$basedir
.
'/crm-uploads'
;
if
(
!
is_dir
(
$path
))
mkdir
(
$path
,
0700
);
$path
.
=
'/'
.
date
(
'Y'
);
if
(
!
is_dir
(
$path
))
mkdir
(
$path
);
if
(
!
is_dir
(
$path
))
mkdir
(
$path
,
0700
);
$path
.
=
'/'
.
date
(
'm'
);
if
(
!
is_dir
(
$path
))
mkdir
(
$path
);
if
(
!
is_dir
(
$path
))
mkdir
(
$path
,
0700
);
$path_info
[
'path'
]
=
$path
;
$url
=
content_url
(
str_replace
(
$basedir
,
''
,
$path
))
.
'/'
;
$path_info
[
'url'
]
=
$url
;
return
$path
;
return
$path
_info
;
};
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment