@@ -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 }
0 commit comments