diff --git a/forms-bridge/addons/bigin/templates/companies.php b/forms-bridge/addons/bigin/templates/companies.php index 5fd1d821..6c0a9f8c 100644 --- a/forms-bridge/addons/bigin/templates/companies.php +++ b/forms-bridge/addons/bigin/templates/companies.php @@ -104,7 +104,7 @@ array( 'name' => 'Phone', 'label' => __( 'Phone', 'forms-bridge' ), - 'type' => 'text', + 'type' => 'tel', ), array( 'name' => 'Description', diff --git a/forms-bridge/addons/bigin/templates/contacts.php b/forms-bridge/addons/bigin/templates/contacts.php index 6110f882..4ec5a013 100644 --- a/forms-bridge/addons/bigin/templates/contacts.php +++ b/forms-bridge/addons/bigin/templates/contacts.php @@ -67,7 +67,7 @@ array( 'name' => 'Phone', 'label' => __( 'Phone', 'forms-bridge' ), - 'type' => 'text', + 'type' => 'tel', ), array( 'name' => 'Description', diff --git a/forms-bridge/addons/bigin/templates/deals.php b/forms-bridge/addons/bigin/templates/deals.php index 69607a40..a48d0828 100644 --- a/forms-bridge/addons/bigin/templates/deals.php +++ b/forms-bridge/addons/bigin/templates/deals.php @@ -168,7 +168,7 @@ array( 'name' => 'Phone', 'label' => __( 'Phone', 'forms-bridge' ), - 'type' => 'text', + 'type' => 'tel', ), array( 'name' => 'Description', diff --git a/forms-bridge/addons/bigin/templates/meetings.php b/forms-bridge/addons/bigin/templates/meetings.php index 6da1ad75..bfd5aaa5 100644 --- a/forms-bridge/addons/bigin/templates/meetings.php +++ b/forms-bridge/addons/bigin/templates/meetings.php @@ -93,7 +93,7 @@ array( 'name' => 'Phone', 'label' => __( 'Phone', 'forms-bridge' ), - 'type' => 'text', + 'type' => 'tel', ), array( 'name' => 'date', diff --git a/forms-bridge/addons/brevo/templates/companies.php b/forms-bridge/addons/brevo/templates/companies.php index af46e814..055ebf8f 100644 --- a/forms-bridge/addons/brevo/templates/companies.php +++ b/forms-bridge/addons/brevo/templates/companies.php @@ -65,7 +65,7 @@ function ( $country ) { array( 'name' => 'phone', 'label' => __( 'Phone', 'forms-bridge' ), - 'type' => 'text', + 'type' => 'tel', ), array( 'name' => 'website', diff --git a/forms-bridge/addons/brevo/templates/company-deals.php b/forms-bridge/addons/brevo/templates/company-deals.php index 3dec9e56..cb8cfb39 100644 --- a/forms-bridge/addons/brevo/templates/company-deals.php +++ b/forms-bridge/addons/brevo/templates/company-deals.php @@ -93,7 +93,7 @@ function ( $country ) { array( 'name' => 'phone', 'label' => __( 'Phone', 'forms-bridge' ), - 'type' => 'text', + 'type' => 'tel', ), array( 'name' => 'website', diff --git a/forms-bridge/addons/dolibarr/templates/individual-leads.php b/forms-bridge/addons/dolibarr/templates/individual-leads.php index 99c57fb8..ff08da87 100644 --- a/forms-bridge/addons/dolibarr/templates/individual-leads.php +++ b/forms-bridge/addons/dolibarr/templates/individual-leads.php @@ -128,7 +128,7 @@ array( 'name' => 'phone', 'label' => __( 'Phone', 'forms-bridge' ), - 'type' => 'text', + 'type' => 'tel', ), array( 'name' => 'note_private', diff --git a/forms-bridge/addons/dolibarr/templates/individual-proposals.php b/forms-bridge/addons/dolibarr/templates/individual-proposals.php index b793e3ef..6b373fdd 100644 --- a/forms-bridge/addons/dolibarr/templates/individual-proposals.php +++ b/forms-bridge/addons/dolibarr/templates/individual-proposals.php @@ -111,7 +111,7 @@ array( 'name' => 'phone', 'label' => __( 'Phone', 'forms-bridge' ), - 'type' => 'text', + 'type' => 'tel', ), array( 'name' => 'address', diff --git a/forms-bridge/addons/dolibarr/templates/individual-prospects.php b/forms-bridge/addons/dolibarr/templates/individual-prospects.php index a0a2e4f7..aa856211 100644 --- a/forms-bridge/addons/dolibarr/templates/individual-prospects.php +++ b/forms-bridge/addons/dolibarr/templates/individual-prospects.php @@ -81,7 +81,7 @@ array( 'name' => 'phone', 'label' => __( 'Phone', 'forms-bridge' ), - 'type' => 'text', + 'type' => 'tel', ), array( 'name' => 'note_private', diff --git a/forms-bridge/addons/dolibarr/templates/thirdparties.php b/forms-bridge/addons/dolibarr/templates/thirdparties.php index cd933cf2..910154d6 100644 --- a/forms-bridge/addons/dolibarr/templates/thirdparties.php +++ b/forms-bridge/addons/dolibarr/templates/thirdparties.php @@ -128,7 +128,7 @@ array( 'name' => 'phone', 'label' => __( 'Phone', 'forms-bridge' ), - 'type' => 'text', + 'type' => 'tel', 'required' => true, ), array( diff --git a/forms-bridge/addons/financoop/templates/donation-requests.php b/forms-bridge/addons/financoop/templates/donation-requests.php index 6ccb699a..71189621 100644 --- a/forms-bridge/addons/financoop/templates/donation-requests.php +++ b/forms-bridge/addons/financoop/templates/donation-requests.php @@ -125,7 +125,7 @@ function ( $country_code ) { array( 'label' => __( 'Phone', 'forms-bridge' ), 'name' => 'phone', - 'type' => 'text', + 'type' => 'tel', 'required' => true, ), array( diff --git a/forms-bridge/addons/financoop/templates/loan-requests.php b/forms-bridge/addons/financoop/templates/loan-requests.php index 68984161..6e9c8a45 100644 --- a/forms-bridge/addons/financoop/templates/loan-requests.php +++ b/forms-bridge/addons/financoop/templates/loan-requests.php @@ -108,7 +108,7 @@ function ( $country_code ) { array( 'label' => __( 'Phone', 'forms-bridge' ), 'name' => 'phone', - 'type' => 'text', + 'type' => 'tel', 'required' => true, ), array( diff --git a/forms-bridge/addons/financoop/templates/subscription-requests.php b/forms-bridge/addons/financoop/templates/subscription-requests.php index 2e8cb30e..218cfc4c 100644 --- a/forms-bridge/addons/financoop/templates/subscription-requests.php +++ b/forms-bridge/addons/financoop/templates/subscription-requests.php @@ -128,7 +128,7 @@ function ( $country_code ) { array( 'label' => __( 'Phone', 'forms-bridge' ), 'name' => 'phone', - 'type' => 'text', + 'type' => 'tel', 'required' => true, ), array( diff --git a/forms-bridge/addons/gsheets/templates/spreadsheet-contacts.json b/forms-bridge/addons/gsheets/templates/spreadsheet-contacts.json index fd68096b..a5ea21dc 100644 --- a/forms-bridge/addons/gsheets/templates/spreadsheet-contacts.json +++ b/forms-bridge/addons/gsheets/templates/spreadsheet-contacts.json @@ -32,7 +32,7 @@ { "name": "phone", "label": "Your phone", - "type": "text" + "type": "tel" } ] }, diff --git a/forms-bridge/addons/holded/templates/appointments.php b/forms-bridge/addons/holded/templates/appointments.php index 5f882f6e..65703f5b 100644 --- a/forms-bridge/addons/holded/templates/appointments.php +++ b/forms-bridge/addons/holded/templates/appointments.php @@ -228,7 +228,7 @@ array( 'label' => __( 'Your phone', 'forms-bridge' ), 'name' => 'phone', - 'type' => 'text', + 'type' => 'tel', 'required' => true, ), array( diff --git a/forms-bridge/addons/holded/templates/company-contacts.php b/forms-bridge/addons/holded/templates/company-contacts.php index 81437061..4f30349c 100644 --- a/forms-bridge/addons/holded/templates/company-contacts.php +++ b/forms-bridge/addons/holded/templates/company-contacts.php @@ -198,7 +198,7 @@ function ( $country_code ) { array( 'label' => __( 'Your phone', 'forms-bridge' ), 'name' => 'phone', - 'type' => 'text', + 'type' => 'tel', 'required' => true, ), ), diff --git a/forms-bridge/addons/holded/templates/company-leads.php b/forms-bridge/addons/holded/templates/company-leads.php index a7e95abe..ceaf7d49 100644 --- a/forms-bridge/addons/holded/templates/company-leads.php +++ b/forms-bridge/addons/holded/templates/company-leads.php @@ -209,7 +209,7 @@ function ( $country_code ) { array( 'label' => __( 'Your phone', 'forms-bridge' ), 'name' => 'phone', - 'type' => 'text', + 'type' => 'tel', 'required' => true, ), ), diff --git a/forms-bridge/addons/holded/templates/contacts.php b/forms-bridge/addons/holded/templates/contacts.php index d71bd6f4..3ae58fe2 100644 --- a/forms-bridge/addons/holded/templates/contacts.php +++ b/forms-bridge/addons/holded/templates/contacts.php @@ -155,7 +155,7 @@ array( 'label' => __( 'Your phone', 'forms-bridge' ), 'name' => 'phone', - 'type' => 'text', + 'type' => 'tel', 'required' => true, ), array( diff --git a/forms-bridge/addons/holded/templates/leads.php b/forms-bridge/addons/holded/templates/leads.php index ad077e46..be96be58 100644 --- a/forms-bridge/addons/holded/templates/leads.php +++ b/forms-bridge/addons/holded/templates/leads.php @@ -168,7 +168,7 @@ array( 'label' => __( 'Your phone', 'forms-bridge' ), 'name' => 'phone', - 'type' => 'text', + 'type' => 'tel', 'required' => true, ), array( diff --git a/forms-bridge/addons/holded/templates/product-company-quotations.php b/forms-bridge/addons/holded/templates/product-company-quotations.php index 44748346..a0c4f892 100644 --- a/forms-bridge/addons/holded/templates/product-company-quotations.php +++ b/forms-bridge/addons/holded/templates/product-company-quotations.php @@ -214,7 +214,7 @@ function ( $country_code ) { array( 'label' => __( 'Your phone', 'forms-bridge' ), 'name' => 'phone', - 'type' => 'text', + 'type' => 'tel', 'required' => true, ), ), diff --git a/forms-bridge/addons/holded/templates/product-quotations.php b/forms-bridge/addons/holded/templates/product-quotations.php index a772eff9..610c596f 100644 --- a/forms-bridge/addons/holded/templates/product-quotations.php +++ b/forms-bridge/addons/holded/templates/product-quotations.php @@ -168,7 +168,7 @@ array( 'label' => __( 'Your phone', 'forms-bridge' ), 'name' => 'phone', - 'type' => 'text', + 'type' => 'tel', 'required' => true, ), array( diff --git a/forms-bridge/addons/holded/templates/service-company-quotations.php b/forms-bridge/addons/holded/templates/service-company-quotations.php index a4086ca2..27220673 100644 --- a/forms-bridge/addons/holded/templates/service-company-quotations.php +++ b/forms-bridge/addons/holded/templates/service-company-quotations.php @@ -214,7 +214,7 @@ function ( $country_code ) { array( 'label' => __( 'Your phone', 'forms-bridge' ), 'name' => 'phone', - 'type' => 'text', + 'type' => 'tel', 'required' => true, ), ), diff --git a/forms-bridge/addons/holded/templates/service-quotations.php b/forms-bridge/addons/holded/templates/service-quotations.php index 3ac09ab1..8cd01a2a 100644 --- a/forms-bridge/addons/holded/templates/service-quotations.php +++ b/forms-bridge/addons/holded/templates/service-quotations.php @@ -168,7 +168,7 @@ array( 'label' => __( 'Your phone', 'forms-bridge' ), 'name' => 'phone', - 'type' => 'text', + 'type' => 'tel', 'required' => true, ), array( diff --git a/forms-bridge/addons/nextcloud/templates/spreadsheet-contacts.json b/forms-bridge/addons/nextcloud/templates/spreadsheet-contacts.json index e6d3c34c..3797c563 100644 --- a/forms-bridge/addons/nextcloud/templates/spreadsheet-contacts.json +++ b/forms-bridge/addons/nextcloud/templates/spreadsheet-contacts.json @@ -32,7 +32,7 @@ { "name": "phone", "label": "Your phone", - "type": "text" + "type": "tel" } ] }, diff --git a/forms-bridge/addons/odoo/templates/appointments.php b/forms-bridge/addons/odoo/templates/appointments.php index 52311060..35981436 100644 --- a/forms-bridge/addons/odoo/templates/appointments.php +++ b/forms-bridge/addons/odoo/templates/appointments.php @@ -140,7 +140,7 @@ array( 'name' => 'phone', 'label' => __( 'Your phone', 'forms-bridge' ), - 'type' => 'text', + 'type' => 'tel', ), array( 'name' => 'date', diff --git a/forms-bridge/addons/odoo/templates/company-contacts.php b/forms-bridge/addons/odoo/templates/company-contacts.php index 269f3c69..9f06c782 100644 --- a/forms-bridge/addons/odoo/templates/company-contacts.php +++ b/forms-bridge/addons/odoo/templates/company-contacts.php @@ -144,7 +144,7 @@ function ( $country_code ) { array( 'label' => __( 'Your phone', 'forms-bridge' ), 'name' => 'phone', - 'type' => 'text', + 'type' => 'tel', ), ), ), diff --git a/forms-bridge/addons/odoo/templates/company-quotations.php b/forms-bridge/addons/odoo/templates/company-quotations.php index e58e9900..34f736ab 100644 --- a/forms-bridge/addons/odoo/templates/company-quotations.php +++ b/forms-bridge/addons/odoo/templates/company-quotations.php @@ -205,7 +205,7 @@ function ( $country_code ) { array( 'label' => __( 'Your phone', 'forms-bridge' ), 'name' => 'phone', - 'type' => 'text', + 'type' => 'tel', ), ), ), diff --git a/forms-bridge/addons/odoo/templates/contacts.php b/forms-bridge/addons/odoo/templates/contacts.php index 42520017..8fc086e7 100644 --- a/forms-bridge/addons/odoo/templates/contacts.php +++ b/forms-bridge/addons/odoo/templates/contacts.php @@ -70,7 +70,7 @@ array( 'label' => __( 'Your phone', 'forms-bridge' ), 'name' => 'phone', - 'type' => 'text', + 'type' => 'tel', ), array( 'label' => __( 'Address', 'forms-bridge' ), diff --git a/forms-bridge/addons/odoo/templates/crm-company-leads.php b/forms-bridge/addons/odoo/templates/crm-company-leads.php index c2b1b1df..d66d1d10 100644 --- a/forms-bridge/addons/odoo/templates/crm-company-leads.php +++ b/forms-bridge/addons/odoo/templates/crm-company-leads.php @@ -221,7 +221,7 @@ function ( $country_code ) { array( 'label' => __( 'Your phone', 'forms-bridge' ), 'name' => 'phone', - 'type' => 'text', + 'type' => 'tel', ), array( 'label' => __( 'Comments', 'forms-bridge' ), diff --git a/forms-bridge/addons/odoo/templates/crm-leads.php b/forms-bridge/addons/odoo/templates/crm-leads.php index 9dc50e04..72687c24 100644 --- a/forms-bridge/addons/odoo/templates/crm-leads.php +++ b/forms-bridge/addons/odoo/templates/crm-leads.php @@ -130,7 +130,7 @@ array( 'label' => __( 'Your phone', 'forms-bridge' ), 'name' => 'phone', - 'type' => 'text', + 'type' => 'tel', ), array( 'label' => __( 'Comments', 'forms-bridge' ), diff --git a/forms-bridge/addons/odoo/templates/crm-team-leads.php b/forms-bridge/addons/odoo/templates/crm-team-leads.php index f6e06bb8..716d8ab4 100644 --- a/forms-bridge/addons/odoo/templates/crm-team-leads.php +++ b/forms-bridge/addons/odoo/templates/crm-team-leads.php @@ -131,7 +131,7 @@ array( 'label' => __( 'Your phone', 'forms-bridge' ), 'name' => 'phone', - 'type' => 'text', + 'type' => 'tel', ), array( 'label' => __( 'Comments', 'forms-bridge' ), diff --git a/forms-bridge/addons/odoo/templates/helpdesk-tickets.php b/forms-bridge/addons/odoo/templates/helpdesk-tickets.php index 820f8d61..fbb2ebf3 100644 --- a/forms-bridge/addons/odoo/templates/helpdesk-tickets.php +++ b/forms-bridge/addons/odoo/templates/helpdesk-tickets.php @@ -109,7 +109,7 @@ array( 'name' => 'your-email', 'label' => __( 'Your email', 'forms-bridge' ), - 'type' => 'text', + 'type' => 'email', 'required' => true, ), array( diff --git a/forms-bridge/addons/odoo/templates/job-applicants.php b/forms-bridge/addons/odoo/templates/job-applicants.php index 1cadc7c3..302a95a2 100644 --- a/forms-bridge/addons/odoo/templates/job-applicants.php +++ b/forms-bridge/addons/odoo/templates/job-applicants.php @@ -122,13 +122,13 @@ array( 'name' => 'your-email', 'label' => __( 'Your email', 'forms-bridge' ), - 'type' => 'text', + 'type' => 'email', 'required' => true, ), array( 'name' => 'your-phone', 'label' => __( 'Your phone', 'forms-bridge' ), - 'type' => 'text', + 'type' => 'tel', 'required' => true, ), array( diff --git a/forms-bridge/addons/odoo/templates/quotations.php b/forms-bridge/addons/odoo/templates/quotations.php index 00aaa837..0e1943e7 100644 --- a/forms-bridge/addons/odoo/templates/quotations.php +++ b/forms-bridge/addons/odoo/templates/quotations.php @@ -116,7 +116,7 @@ array( 'label' => __( 'Your phone', 'forms-bridge' ), 'name' => 'phone', - 'type' => 'text', + 'type' => 'tel', 'required' => true, ), array( diff --git a/forms-bridge/addons/zoho/templates/accounts.php b/forms-bridge/addons/zoho/templates/accounts.php index d84e31ce..163a91b9 100644 --- a/forms-bridge/addons/zoho/templates/accounts.php +++ b/forms-bridge/addons/zoho/templates/accounts.php @@ -103,7 +103,7 @@ array( 'name' => 'Phone', 'label' => __( 'Phone', 'forms-bridge' ), - 'type' => 'text', + 'type' => 'tel', ), array( 'name' => 'Title', diff --git a/forms-bridge/addons/zoho/templates/company-leads.php b/forms-bridge/addons/zoho/templates/company-leads.php index 14fdf894..da448baa 100644 --- a/forms-bridge/addons/zoho/templates/company-leads.php +++ b/forms-bridge/addons/zoho/templates/company-leads.php @@ -161,7 +161,7 @@ array( 'name' => 'Phone', 'label' => __( 'Phone', 'forms-bridge' ), - 'type' => 'text', + 'type' => 'tel', ), array( 'name' => 'Title', diff --git a/forms-bridge/addons/zoho/templates/contacts.php b/forms-bridge/addons/zoho/templates/contacts.php index bbaa662e..4869dcda 100644 --- a/forms-bridge/addons/zoho/templates/contacts.php +++ b/forms-bridge/addons/zoho/templates/contacts.php @@ -68,7 +68,7 @@ array( 'name' => 'Phone', 'label' => __( 'Phone', 'forms-bridge' ), - 'type' => 'text', + 'type' => 'tel', ), array( 'name' => 'Description', diff --git a/forms-bridge/addons/zoho/templates/leads.php b/forms-bridge/addons/zoho/templates/leads.php index 8b3a3281..ef7434a9 100644 --- a/forms-bridge/addons/zoho/templates/leads.php +++ b/forms-bridge/addons/zoho/templates/leads.php @@ -129,7 +129,7 @@ array( 'name' => 'Phone', 'label' => __( 'Phone', 'forms-bridge' ), - 'type' => 'text', + 'type' => 'tel', ), array( 'name' => 'Description', diff --git a/forms-bridge/addons/zoho/templates/meetings.php b/forms-bridge/addons/zoho/templates/meetings.php index c049ec61..ecaf37d5 100644 --- a/forms-bridge/addons/zoho/templates/meetings.php +++ b/forms-bridge/addons/zoho/templates/meetings.php @@ -146,7 +146,7 @@ array( 'name' => 'Phone', 'label' => __( 'Phone', 'forms-bridge' ), - 'type' => 'text', + 'type' => 'tel', ), array( 'name' => 'date', diff --git a/forms-bridge/includes/jobs/date-fields-to-date.php b/forms-bridge/includes/jobs/date-fields-to-date.php index 880d5a31..4b7ee484 100644 --- a/forms-bridge/includes/jobs/date-fields-to-date.php +++ b/forms-bridge/includes/jobs/date-fields-to-date.php @@ -59,7 +59,11 @@ function forms_bridge_job_format_date_fields( $payload ) { true ); - $date_format = $form_data['fields'][ $date_index ]['format'] ?? ''; + if ( false !== $date_index ) { + $date_format = $form_data['fields'][ $date_index ]['format']; + } else { + $date_format = 'yyyy-mm-dd'; + } if ( strstr( $date_format, '-' ) ) { $separator = '-'; diff --git a/forms-bridge/integrations/formidable/class-formidable-integration.php b/forms-bridge/integrations/formidable/class-formidable-integration.php index bc274d05..cbd67da7 100644 --- a/forms-bridge/integrations/formidable/class-formidable-integration.php +++ b/forms-bridge/integrations/formidable/class-formidable-integration.php @@ -139,7 +139,8 @@ public function create_form( $data ) { $field_values = array_merge( $field_values, $field ); $field_values['field_options']['draft'] = 0; - $field_values = apply_filters( 'frm_before_field_created', $field_values ); + + $field_values = apply_filters( 'frm_before_field_created', $field_values ); FrmField::create( $field_values ); } @@ -330,6 +331,13 @@ private function serialize_field( $field ) { $type = 'mixed'; break; case 'checkbox': + if ( 1 === count( $options ) && '1' === $options[0]['value'] ) { + $type = 'checkbox'; + } else { + $type = 'select'; + } + + break; case 'select': case 'radio': case 'lookup': @@ -364,14 +372,6 @@ private function serialize_field( $field ) { break; case 'hidden': $type = 'hidden'; - break; - case 'toggle': - if ( is_array( $field->options ) && '' === ( $field->options[0] ?? false ) && '1' === ( $field->options[1] ?? false ) ) { - $type = 'checkbox'; - } else { - $type = 'text'; - } - break; default: $type = 'text'; @@ -387,10 +387,10 @@ private function serialize_field( $field ) { 'required' => (bool) $field->required, 'options' => $options, 'is_file' => 'file' === $field->type, - 'is_multi' => $this->is_multi_field( $field ), + 'is_multi' => $this->is_multi_field( $field, $type ), 'conditional' => ! empty( $field->field_options['hide_field'] ) && ! empty( $field->field_options['hide_opt'] ), 'format' => 'date' === $field->type ? 'yyyy-mm-dd' : '', - 'schema' => $this->field_value_schema( $field ), + 'schema' => $this->field_value_schema( $field, $type ), 'basetype' => $field->type, 'form_id' => $field->form_id, ), @@ -405,10 +405,11 @@ private function serialize_field( $field ) { * Checks if a field is multi-value field. * * @param object $field Target field instance. + * @param string $norm_type Normalized field type. * * @return boolean */ - private function is_multi_field( $field ) { + private function is_multi_field( $field, $norm_type ) { if ( 'file' === $field->type ) { return boolval( $field->field_options['multiple'] ?? false ); } @@ -417,7 +418,11 @@ private function is_multi_field( $field ) { return boolval( $field->options['is_range_slider'] ?? false ); } - if ( in_array( $field->type, array( 'repeater', 'checkbox', 'address', 'credit_card' ), true ) ) { + if ( 'checkbox' === $field->type && 'select' === $norm_type ) { + return true; + } + + if ( in_array( $field->type, array( 'repeater', 'address', 'credit_card' ), true ) ) { return true; } @@ -428,10 +433,11 @@ private function is_multi_field( $field ) { * Gets the field value JSON schema. * * @param object $field Field instance. + * @param string $norm_type Normalized field type. * * @return array|null JSON schema of the value of the field. */ - private function field_value_schema( $field ) { + private function field_value_schema( $field, $norm_type ) { switch ( $field->type ) { case 'form': $embedded = FrmForm::getOne( $field->field_options['form_select'] ); @@ -472,12 +478,6 @@ private function field_value_schema( $field ) { case 'total': case 'number': return array( 'type' => 'number' ); - case 'checkbox': - return array( - 'type' => 'array', - 'items' => array( 'type' => 'string' ), - 'additionalItems' => false, - ); case 'credit_card': return array( 'type' => 'object', @@ -530,14 +530,16 @@ private function field_value_schema( $field ) { return array( 'type' => $type ); case 'file': return null; - case 'toggle': - if ( is_array( $field->options ) && '' === ( $field->options[0] ?? false ) && '1' === ( $field->options[1] ?? false ) ) { - $type = 'boolean'; + case 'checkbox': + if ( 'checkbox' === $norm_type ) { + return array( 'type' => 'boolean' ); } else { - $type = 'text'; + return array( + 'type' => 'array', + 'items' => array( 'type' => 'string' ), + 'additionalItems' => true, + ); } - - return array( 'type' => $type ); default: return array( 'type' => 'string' ); } @@ -603,6 +605,8 @@ public function serialize_submission( $submission, $form_data ) { $data[ $field_name ] = $value; } } + } elseif ( 'checkbox' === $field['type'] ) { + $data[ $field_name ] = false; } } @@ -634,13 +638,22 @@ private function format_value( $value, $field ) { case 'number': return (float) $value; case 'checkbox': - $value = maybe_unserialize( $value ); + $value = maybe_unserialize( $value ); + $is_boolean = 'checkbox' === $field['type']; if ( is_array( $value ) ) { + if ( $is_boolean ) { + return (bool) $value[0] ?? false; + } + return array_filter( $value ); - } else { - return array( $value ); } + + if ( $is_boolean ) { + return (bool) $value; + } + + return array( $value ); case 'select': if ( is_array( $value ) ) { return array_filter( $value ); @@ -664,8 +677,6 @@ private function format_value( $value, $field ) { } return $value; - case 'toggle': - return 'checkbox' === $field['type'] ? boolval( $value ) : $value; default: return (string) $value; } @@ -795,9 +806,12 @@ private function prepare_fields( $fields ) { $formidable_fields[] = $this->date_field( $args ); break; case 'file': - $args['is_multi'] = $field['is_multi'] ?? false; - $args['filetypes'] = $field['filetypes'] ?? ''; - $formidable_fields[] = $this->file_field( $args ); + if ( $this->full_support() ) { + $args['is_multi'] = $field['is_multi'] ?? false; + $args['filetypes'] = $field['filetypes'] ?? ''; + $formidable_fields[] = $this->file_field( $args ); + } + break; case 'text': default: @@ -945,6 +959,12 @@ private function text_field( $args ) { * @return array */ private function date_field( $args ) { + if ( ! $this->full_support() ) { + $args['default_value'] = 'yyyy-mm-dd'; + $args['placeholder'] = 'yyyy-mm-dd'; + return $this->field_template( 'text', $args, array( 'format' => '^\d{4}-\d{1,2}-\d{1,2}' ) ); + } + return $this->field_template( 'date', $args ); } @@ -967,8 +987,24 @@ private function number_field( $args ) { * @return array */ private function checkbox_field( $args ) { - $args['options'] = array( '', '1' ); - return $this->field_template( 'toggle', $args ); + $args['options'] = array( + array( + 'label' => $args['name'], + 'value' => '1', + 'image' => 0, + ), + ); + + return $this->field_template( 'checkbox', $args ); + } + + /** + * Returns true if the formidable pro version is installed. + * + * @return boolean + */ + private function full_support() { + return (bool) apply_filters( 'frm_pro_installed', false ); } } diff --git a/forms-bridge/integrations/ninja/class-ninja-integration.php b/forms-bridge/integrations/ninja/class-ninja-integration.php index 4e1275a2..d425a666 100644 --- a/forms-bridge/integrations/ninja/class-ninja-integration.php +++ b/forms-bridge/integrations/ninja/class-ninja-integration.php @@ -127,7 +127,8 @@ public function create_form( $data ) { $form_data['settings']['formContentData'] = $field['settings']['key']; } - $form = Ninja_Forms()->form()->get(); + $form_id = defined( 'WP_TESTS_DOMAIN' ) ? rand( 1, 1000 ) : ''; + $form = Ninja_Forms()->form( $form_id )->get(); $form->save(); $form_data['id'] = $form->get_id(); @@ -765,9 +766,18 @@ private function decorate_form_fields( $fields ) { $nf_fields[] = $this->date_field( ...$args ); break; case 'file': - $args[] = $field['is_multi'] ?? false; - $args[] = $field['filetypes'] ?? ''; - $nf_fields[] = $this->upload_field( ...$args ); + if ( ! class_exists( 'NF_FU_File_Uploads' ) ) { + if ( function_exists( 'NF_File_Uploads' ) ) { + NF_File_Uploads(); + } + } + + if ( class_exists( 'NF_FU_File_Uploads' ) ) { + $args[] = $field['is_multi'] ?? false; + $args[] = $field['filetypes'] ?? ''; + $nf_fields[] = $this->upload_field( ...$args ); + } + break; case 'hidden': if ( isset( $field['value'] ) ) { diff --git a/forms-bridge/integrations/wpforms/class-wpforms-integration.php b/forms-bridge/integrations/wpforms/class-wpforms-integration.php index f82d078f..9a0ca688 100644 --- a/forms-bridge/integrations/wpforms/class-wpforms-integration.php +++ b/forms-bridge/integrations/wpforms/class-wpforms-integration.php @@ -362,9 +362,15 @@ private function serialize_field( $field, $fields = array(), $all_fields = array case 'payment-multiple': case 'payment-checkbox': case 'select': - case 'checkbox': $type = 'select'; break; + case 'checkbox': + if ( 1 === count( $options ) && '1' === $options[0]['value'] ) { + $type = 'checkbox'; + } else { + $type = 'select'; + } + break; case 'number-slider': case 'number': $type = 'number'; @@ -402,11 +408,11 @@ private function serialize_field( $field, $fields = array(), $all_fields = array 'required' => '1' === ( $field['required'] ?? '' ), 'options' => $options, 'is_file' => 'file-upload' === $field['type'], - 'is_multi' => $this->is_multi_field( $field ), + 'is_multi' => $this->is_multi_field( $field, $type ), 'conditional' => false, 'format' => $format, 'children' => array_values( $children ), - 'schema' => $this->field_value_schema( $field, $children ), + 'schema' => $this->field_value_schema( $field, $type, $children ), 'basetype' => $field['type'], ), $field, @@ -417,12 +423,17 @@ private function serialize_field( $field, $fields = array(), $all_fields = array /** * Checks if a filed is multi value field. * - * @param array $field Target field instance. + * @param array $field Target field instance. + * @param string $norm_type Normalized field type. * * @return boolean */ - private function is_multi_field( $field ) { - if ( 'checkbox' === $field['type'] || 'repeater' === $field['type'] ) { + private function is_multi_field( $field, $norm_type ) { + if ( 'checkbox' === $field['type'] && 'select' === $norm_type ) { + return true; + } + + if ( 'repeater' === $field['type'] ) { return true; } @@ -443,12 +454,13 @@ private function is_multi_field( $field ) { /** * Gets the field value JSON schema. * - * @param array $field Field instance. - * @param array $children Children fields. + * @param array $field Field instance. + * @param string $norm_type Normalized field type. + * @param array $children Children fields. * * @return array JSON schema of the value of the field. */ - private function field_value_schema( $field, $children = array() ) { + private function field_value_schema( $field, $norm_type, $children = array() ) { switch ( $field['type'] ) { case 'name': case 'email': @@ -483,6 +495,10 @@ private function field_value_schema( $field, $children = array() ) { return array( 'type' => 'string' ); case 'checkbox': + if ( 'checkbox' === $norm_type ) { + return array( 'type' => 'boolean' ); + } + $items = array(); $count = count( $field['choices'] ); for ( $i = 0; $i < $count; $i++ ) { @@ -582,18 +598,28 @@ public function serialize_submission( $submission, $form_data ) { } } - foreach ( $submission['fields'] as $field ) { - if ( 'file-upload' === $field['type'] ) { + $submission_fields = array_values( $submission['fields'] ); + + foreach ( $form_data['fields'] as $field_data ) { + if ( 'file' === $field_data['type'] ) { continue; } - $i = array_search( - trim( $field['name'] ), - array_column( $form_data['fields'], 'name' ), + $index = array_search( + trim( $field_data['name'] ), + array_column( $submission_fields, 'name' ), true ); - $field_data = $form_data['fields'][ $i ]; + if ( false === $index ) { + if ( 'checkbox' === $field_data['type'] ) { + $data[ $field_data['name'] ] = false; + } + + continue; + } + + $field = $submission_fields[ $index ]; $field['id'] = preg_replace( '/_\d+$/', '', $field['id'] ); if ( isset( $fields_in_repeaters[ $field['id'] ] ) ) { @@ -661,7 +687,7 @@ private function format_value( $field, $field_data ) { if ( 'select' === $field_data['basetype'] || - 'checkbox' === $field_data['basetype'] + 'checkbox' === $field_data['basetype'] && 'select' === $field_data['type'] ) { if ( $field_data['is_multi'] ) { return array_map( @@ -673,6 +699,10 @@ function ( $value ) { } } + if ( 'checkbox' === $field_data['basetype'] && 'checkbox' === $field_data['type'] ) { + return (bool) $field['value']; + } + if ( 'address' === $field_data['basetype'] ) { $post_values = $_POST['wpforms']['fields'][ $field['id'] ] ?? array(); $field_values = array(); @@ -768,12 +798,13 @@ private function encode_form_data( $data ) { $wp_fields[ strval( $id ) ] = $this->textarea_field( ...$args ); break; case 'hidden': - if ( isset( $field['value'] ) ) { + if ( $this->full_support() && isset( $field['value'] ) ) { if ( is_bool( $field['value'] ) ) { $field['value'] = $field['value'] ? '1' : '0'; } - $args[] = (string) $field['value']; + $args[] = (string) $field['value']; + $wp_fields[ strval( $id ) ] = $this->hidden_field( ...$args ); } @@ -787,8 +818,11 @@ private function encode_form_data( $data ) { $wp_fields[ strval( $id ) ] = $this->checkbox_field( ...$args ); break; case 'file': - $args[] = $field['filetypes'] ?? ''; - $wp_fields[ strval( $id ) ] = $this->file_field( ...$args ); + if ( $this->full_support() ) { + $args[] = $field['filetypes'] ?? ''; + $wp_fields[ strval( $id ) ] = $this->file_field( ...$args ); + } + break; case 'date': $wp_fields[ strval( $id ) ] = $this->date_field( ...$args ); @@ -808,12 +842,26 @@ private function encode_form_data( $data ) { $wp_fields[ strval( $id ) ] = $this->number_field( ...$args ); break; case 'tel': - $wp_fields[ strval( $id ) ] = $this->field_template( - 'phone', - ...$args - ); + if ( ! $this->full_support() ) { + $wp_field = $this->field_template( 'text', ...$args ); + } else { + $wp_field = $this->field_template( 'phone', ...$args ); + } + + $wp_fields[ strval( $id ) ] = $wp_field; break; case 'url': + if ( ! $this->full_support() ) { + $wp_field = array_merge( + $this->field_template( 'text', ...$args ), + array( 'input_mask' => 'alias:url' ), + ); + } else { + $wp_field = $this->field_template( 'url', ...$args ); + } + + $wp_fields[ strval( $id ) ] = $wp_field; + break; case 'email': default: $wp_fields[ strval( $id ) ] = $this->field_template( @@ -918,7 +966,7 @@ private function checkbox_field( $id, $name, $required ) { 'choices' => array( array( 'label' => $name, - 'value' => __( 'Checked', 'forms-bridge' ), + 'value' => '1', 'image' => '', 'icon' => '', 'icon_style' => 'regular', @@ -956,6 +1004,13 @@ private function number_field( $id, $name, $required, $constraints ) { * @return array */ private function date_field( $id, $name, $required ) { + if ( ! $this->full_support() ) { + return array_merge( + $this->field_template( 'text', $id, $name, $required ), + array( 'input_mask' => 'date:yyyy-mm-dd' ), + ); + } + return array_merge( $this->field_template( 'date-time', $id, $name, $required ), array( @@ -1084,6 +1139,15 @@ private function file_field( $id, $name, $required, $filetypes ) { ) ); } + + /** + * Returns true if the wpforms pro version is installed. + * + * @return boolean + */ + private function full_support() { + return (bool) wpforms()->is_pro(); + } } WPForms_Integration::setup(); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 936fdc06..82033887 100755 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -88,6 +88,15 @@ function is_user_logged_in() { 20, ); + // Ninja forms hooks + add_action( + 'init', + function () { + Ninja_Forms()->activation(); + }, + 9, + ); + /* Plugin tests */ require dirname( __DIR__ ) . '/forms-bridge/deps/plugin/tests/bootstrap.php'; } diff --git a/tests/integrations/class-base-integration-test.php b/tests/integrations/class-base-integration-test.php index d4c494a7..50ee7820 100644 --- a/tests/integrations/class-base-integration-test.php +++ b/tests/integrations/class-base-integration-test.php @@ -254,11 +254,33 @@ public function run_test_form_templates() { $form_data = $integration->get_form_by_id( $form_id ); + // Skip numeration of duplicated form titles + $form_title = substr( $form_data['title'], 0, strlen( $data['title'] ) ); + $this->assertSame( $form_title, $data['title'] ); + $l = count( $data['fields'] ); for ( $i = 0; $i < $l; $i++ ) { $template_field = $data['fields'][ $i ]; $form_field = $form_data['fields'][ $i ]; + // Field serialization exceptions by integration + if ( 'formidable' === $integration::NAME ) { + if ( 'date' === $template_field['type'] ) { + $this->assertSame( 'text', $form_field['type'] ); + continue; + } + } elseif ( 'wpforms' === $integration::NAME ) { + if ( 'date' === $template_field['type'] || 'url' === $template_field['type'] ) { + $this->assertSame( 'text', $form_field['type'] ); + continue; + } + } elseif ( 'ninja' === $integration::NAME ) { + if ( 'url' === $template_field['type'] ) { + $this->assertSame( 'text', $form_field['type'] ); + continue; + } + } + $this->assertSame( $template_field['type'], $form_field['type'] ); } } diff --git a/tests/integrations/test-ninja-forms.php b/tests/integrations/test-ninja-forms.php index 5ea9b68c..2b3f6295 100644 --- a/tests/integrations/test-ninja-forms.php +++ b/tests/integrations/test-ninja-forms.php @@ -390,4 +390,8 @@ public function test_questionnaire_submission_serialization() { ); $this->assertEquals( 3, $payload['starrating_1762818417160'] ); } + + public function test_form_templates() { + $this->run_test_form_templates(); + } } diff --git a/tests/integrations/test-wpforms.php b/tests/integrations/test-wpforms.php index eb967153..f0ca10e3 100644 --- a/tests/integrations/test-wpforms.php +++ b/tests/integrations/test-wpforms.php @@ -276,4 +276,8 @@ public function test_meeting_room_registration_submission_serialization() { $payload['Which time blocks would you like to reserve?'] ); } + + public function test_form_templates() { + $this->run_test_form_templates(); + } }