Skip to content

Commit 858e016

Browse files
committed
feat: formidable use field label as name
1 parent c92c92c commit 858e016

File tree

3 files changed

+32
-38
lines changed

3 files changed

+32
-38
lines changed

forms-bridge/includes/class-form-bridge-template.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,7 @@ static function ( $field ) {
927927

928928
if ( 'woo' === $integration ) {
929929
$data['form']['id'] = 1;
930-
} elseif ( 'wpforms' === $integration ) {
930+
} elseif ( in_array( $integration, array( 'wpforms', 'formidable' ), true ) ) {
931931
$mappers = array();
932932
foreach ( $data['form']['fields'] as &$field ) {
933933
if ( 'file' !== $field['type'] ) {

forms-bridge/integrations/formidable/class-formidable-integration.php

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -304,14 +304,12 @@ public function serialize_form( $form ) {
304304
* @return array|null
305305
*/
306306
private function serialize_field( $field ) {
307-
// Skip non-input fields.
308-
if ( in_array( $field->type, array( 'data', 'summary', 'break', 'end_divider', 'divider', 'html', 'captcha', 'submit' ), true ) ) {
307+
$skip_fields = array( 'data', 'summary', 'break', 'end_divider', 'divider', 'html', 'captcha', 'submit' );
308+
309+
if ( in_array( $field->type, $skip_fields, true ) ) {
309310
return null;
310311
}
311312

312-
$label = $field->name ?: $field->description;
313-
$name = $field->field_key ?: $label;
314-
315313
$options = array();
316314
if ( isset( $field->options ) && is_array( $field->options ) ) {
317315
foreach ( $field->options as $option ) {
@@ -376,8 +374,8 @@ private function serialize_field( $field ) {
376374
array(
377375
'id' => $field->id,
378376
'type' => $type,
379-
'name' => trim( $name ),
380-
'label' => trim( $label ),
377+
'name' => trim( $field->name ),
378+
'label' => trim( $field->name ),
381379
'required' => $field->required,
382380
'options' => $options,
383381
'is_file' => 'file' === $field->type,
@@ -550,8 +548,8 @@ public function serialize_submission( $submission, $form_data ) {
550548
continue;
551549
}
552550

553-
$field_name = $field['name'];
554-
$field_id = $field['id'];
551+
$field_name = trim( $field['name'] );
552+
$field_id = absint( $field['id'] );
555553
$value = $by_field_id[ $field_id ] ?? null;
556554

557555
if ( null !== $value ) {
@@ -653,7 +651,7 @@ private function format_value( $value, $field_type ) {
653651
default:
654652
return (string) $value;
655653
}
656-
} catch ( TypeError $e ) {
654+
} catch ( TypeError ) {
657655
return $value;
658656
}
659657
}
@@ -719,7 +717,7 @@ protected function submission_uploads( $submission, $form_data ) {
719717
}
720718

721719
if ( ! empty( $paths ) ) {
722-
$uploads[ $field['name'] ] = array(
720+
$uploads[ trim( $field['name'] ) ] = array(
723721
'path' => $field['is_multi'] ? $paths : $paths[0],
724722
'is_multi' => $field['is_multi'],
725723
);
@@ -738,12 +736,12 @@ protected function submission_uploads( $submission, $form_data ) {
738736
*/
739737
private function prepare_fields( $fields ) {
740738
$formidable_fields = array();
741-
$count = count( $fields );
739+
740+
$count = count( $fields );
742741
for ( $i = 0; $i < $count; $i++ ) {
743742
$field = $fields[ $i ];
744743
$args = array(
745-
'name' => $field['name'],
746-
'label' => $field['label'] ?? '',
744+
'name' => $field['label'],
747745
'required' => $field['required'] ?? false,
748746
'default_value' => $field['value'] ?? '',
749747
);
@@ -806,13 +804,13 @@ private function field_template( $type, $args, $options = array() ) {
806804
$args,
807805
array(
808806
'type' => $type,
809-
'field_key' => $args['name'] ?? 'untitled',
810-
'name' => $args['label'] ?? 'Untitled',
811-
'required' => $args['required'] ?? '',
807+
'field_key' => sanitize_title( $args['name'] ),
808+
'name' => $args['name'],
809+
'required' => $args['required'] ?? false,
812810
'description' => '',
813811
'options' => $args['options'] ?? '',
814812
'field_options' => $options,
815-
'multiple' => $args['is_multi'] ?? 0,
813+
'multiple' => $args['is_multi'] ?? false,
816814
),
817815
);
818816
}

forms-bridge/integrations/wpforms/class-wpforms-integration.php

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,18 @@
2222
* WPForms integration.
2323
*/
2424
class WPForms_Integration extends BaseIntegration {
25-
25+
/**
26+
* Handles integration name.
27+
*
28+
* @var string
29+
*/
2630
const NAME = 'wpforms';
2731

32+
/**
33+
* Handles integration title.
34+
*
35+
* @var string
36+
*/
2837
const TITLE = 'WP Forms';
2938

3039
/**
@@ -278,26 +287,13 @@ public function serialize_form( $form ) {
278287
* @param array[] $fields List of serialized fields.
279288
* @param array[] $all_fields Complete list of form data fields.
280289
*
281-
* @return array
290+
* @return array|null
282291
*/
283292
private function serialize_field( $field, $fields = array(), $all_fields = array() ) {
284-
if (
285-
in_array(
286-
$field['type'],
287-
array(
288-
'submit',
289-
'pagebreak',
290-
'layout',
291-
'captcha',
292-
'content',
293-
'entry-preview',
294-
'html',
295-
'divider',
296-
),
297-
true
298-
)
299-
) {
300-
return;
293+
$skip_fields = array( 'submit', 'pagebreak', 'layout', 'captcha', 'content', 'entry-preview', 'html', 'divider' );
294+
295+
if ( in_array( $field['type'], $skip_fields, true ) ) {
296+
return null;
301297
}
302298

303299
$repeaters = array();

0 commit comments

Comments
 (0)