From: soufiane Date: Tue, 27 Aug 2024 16:10:50 +0000 (+0200) Subject: wait #7041 @7:00 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=302520514ea413dfdc1c6ffa9aa10cae68152278;p=ccv-wordpress.git wait #7041 @7:00 --- diff --git a/wp-content/mu-plugins/cube/src/Forms/Base.php b/wp-content/mu-plugins/cube/src/Forms/Base.php index f88a137..164c028 100644 --- a/wp-content/mu-plugins/cube/src/Forms/Base.php +++ b/wp-content/mu-plugins/cube/src/Forms/Base.php @@ -246,39 +246,60 @@ class Base $charset = get_bloginfo('charset'); $headers[] = sprintf('Content-Type: %s; charset=%s', $content_type, $charset); $headers[] = sprintf('From: %s', $from); + $first_data_names = [ + 'date-first-symptoms', + 'imagery-condition', + 'chirurgical-solutions' + ]; // Gather filled fields into label/value pairs + foreach ($first_data_names as $first_data_name) { + if($this->fields[$first_data_name]) { + $data[$this->fields[$first_data_name]->get_title()] = $this->get_data($first_data_name); + } + } foreach ($this->fields as $field_name => $field) { - if ($value = $this->get_data($field_name)) { - $data[$field->get_title()] = $value; + if(!in_array($field_name,$first_data_names)) { + if ($value = $this->get_data($field_name)) { + $data[$field->get_title()] = $value; + } } } $message = view('forms.common.email', compact('data', 'subject')); - // Hook directly into WPMailer temporarily so we can add attachments and set their proper filenames - add_action('phpmailer_init', [$this, 'attach_files']); - $success = wp_mail($to, $subject, $message, $headers); - remove_action('phpmailer_init', [$this, 'attach_files']); - - if ($success) { - wp_send_json([ - 'message' => [ - 'type' => 'success', - 'text' => $this->config['success_message'], - ], - 'hide_form' => true, - ]); - } else { + if($this->get_data('social-cover') === __('Accident du travail') && empty($this->get_data('work-accident'))) { wp_send_json([ 'message' => [ 'type' => 'error', - 'text' => __("Erreur d'envoi du message. Veuillez réessayer.", "ccv"), + 'text' => __("Veuillez indiquer une date d'accident de travail.", "ccv"), ] ]); + } else { + // Hook directly into WPMailer temporarily so we can add attachments and set their proper filenames + add_action('phpmailer_init', [$this, 'attach_files']); + $success = wp_mail($to, $subject, $message, $headers); + remove_action('phpmailer_init', [$this, 'attach_files']); + + if ($success) { + wp_send_json([ + 'message' => [ + 'type' => 'success', + 'text' => $this->config['success_message'], + ], + 'hide_form' => true, + ]); + } else { + wp_send_json([ + 'message' => [ + 'type' => 'error', + 'text' => __("Erreur d'envoi du message. Veuillez réessayer.", "ccv"), + ] + ]); + } + $this->post_process(); } - $this->post_process(); } public function post_process() {} diff --git a/wp-content/mu-plugins/cube/src/Forms/Builder/Fields/Text.php b/wp-content/mu-plugins/cube/src/Forms/Builder/Fields/Text.php index 4e27b31..b2052b5 100644 --- a/wp-content/mu-plugins/cube/src/Forms/Builder/Fields/Text.php +++ b/wp-content/mu-plugins/cube/src/Forms/Builder/Fields/Text.php @@ -9,9 +9,8 @@ class Text extends Field public function render($settings) { $name = $this->name; $type = "text"; - $attr = ""; + $attr = "data-parsley-valid-if='[data-parsley-id=170]'"; if(strstr($name,'link')) { - $attr = "data-parsley-type='url'"; $type = "url"; } return ''; diff --git a/wp-content/mu-plugins/cube/src/Forms/Consultation.php b/wp-content/mu-plugins/cube/src/Forms/Consultation.php index 643b13d..da779dd 100644 --- a/wp-content/mu-plugins/cube/src/Forms/Consultation.php +++ b/wp-content/mu-plugins/cube/src/Forms/Consultation.php @@ -81,7 +81,7 @@ class Consultation extends Base { 'Dr Caroline HIRSH' => 'dr.hirsch@ccv-montpellier.fr', ]), - Date::field('work-accident', __('Si accident de travail à quelle date ? ')), + Date::field('work-accident', __('Si accident de travail à quelle date ? '))->required(false), //=== IMAGERY // This is a special case and will be output manually so only using this for the e-mail label @@ -144,23 +144,23 @@ class Consultation extends Base { Binary::field('rheumatological', __('Suivi rhumatologique ou médecine spécialisée', 'ccv')), Textarea::field('surgeries', __('Indiquez ici vos précédentes chirurgies de la colonne et leurs dates (le cas échéant)', 'ccv'))->required(false), - Radio::field('imagery-condition', __('', 'ccv')) + Radio::field('imagery-condition', __('IRM de moins de 6 mois', 'ccv')) ->options([ __('J\'ai bien noté que mon dossier ne pourra être étudié si je fournis pas une IRM de moins de 6 mois', 'ccv'), ]), - Text::field('link-1', __('Lien internet 1', 'ccv')), - Text::field('id-1', __('Identifiant', 'ccv')), - Password::field('pwd-1', __('Mot de passe', 'ccv')), - Text::field('link-2', __('Lien internet 2', 'ccv')), - Text::field('id-2', __('Identifiant 2', 'ccv')), - Password::field('pwd-2', __('Mot de passe 2', 'ccv')), - Text::field('link-3', __('Lien internet 3', 'ccv')), - Text::field('id-3', __('Identifiant 3', 'ccv')), - Password::field('pwd-3', __('Mot de passe 3', 'ccv')), - Text::field('link-4', __('Lien internet 4', 'ccv')), - Text::field('id-4', __('Identifiant 4', 'ccv')), - Password::field('pwd-4', __('Mot de passe 4', 'ccv')), + Text::field('link-1', __('Lien internet 1', 'ccv'))->required(false), + Text::field('id-1', __('Identifiant', 'ccv'))->required(false), + Password::field('pwd-1', __('Mot de passe', 'ccv'))->required(false), + Text::field('link-2', __('Lien internet 2', 'ccv'))->required(false), + Text::field('id-2', __('Identifiant 2', 'ccv'))->required(false), + Password::field('pwd-2', __('Mot de passe 2', 'ccv'))->required(false), + Text::field('link-3', __('Lien internet 3', 'ccv'))->required(false), + Text::field('id-3', __('Identifiant 3', 'ccv'))->required(false), + Password::field('pwd-3', __('Mot de passe 3', 'ccv'))->required(false), + Text::field('link-4', __('Lien internet 4', 'ccv'))->required(false), + Text::field('id-4', __('Identifiant 4', 'ccv'))->required(false), + Password::field('pwd-4', __('Mot de passe 4', 'ccv'))->required(false), ]); } @@ -189,5 +189,9 @@ class Consultation extends Base { $this->set_destination($surgeons[$this->get_data('surgeon')]); } } + + if($this->form_title === "appointment") { + $this->remove_field('surgeon'); + } } } diff --git a/wp-content/themes/CCV/resources/assets/scripts/forms/forms.js b/wp-content/themes/CCV/resources/assets/scripts/forms/forms.js index 784f142..b3d0747 100644 --- a/wp-content/themes/CCV/resources/assets/scripts/forms/forms.js +++ b/wp-content/themes/CCV/resources/assets/scripts/forms/forms.js @@ -95,6 +95,7 @@ function createRequestHandler (formEl) { // Should we hide form? if (response.hide_form) { formEl.querySelector('.cube-form-content').style.display = 'none' + formEl.querySelector('.cube-form-message').style.display = 'none' } // Should we redirect? diff --git a/wp-content/themes/CCV/resources/assets/scripts/forms/parsley-setup.js b/wp-content/themes/CCV/resources/assets/scripts/forms/parsley-setup.js index dc4043e..e44cc8e 100644 --- a/wp-content/themes/CCV/resources/assets/scripts/forms/parsley-setup.js +++ b/wp-content/themes/CCV/resources/assets/scripts/forms/parsley-setup.js @@ -16,6 +16,22 @@ $('.cube-form').parsley(parsleyConfig); + $('[name=social-cover]').on('change', function() { + var isChecked = $(this).is(':checked'); + if (isChecked) { + let val = $(this).val() + if (val === 'Accident du travail') { + $('[name=work-accident]').attr('data-parsley-required', 'true').attr('required'); + } else { + $('[name=work-accident]').attr('data-parsley-required', 'false').removeAttr('required'); + } + } + + // Re-validate the form to apply the changes + $('[name=work-accident]').parsley().validate(); + }); + + // On validation errors, scroll to the first invalid input $.listen('parsley:field:error', function() { diff --git a/wp-content/themes/CCV/resources/views/partials/content-form.blade.php b/wp-content/themes/CCV/resources/views/partials/content-form.blade.php index 4b38004..f94ae98 100644 --- a/wp-content/themes/CCV/resources/views/partials/content-form.blade.php +++ b/wp-content/themes/CCV/resources/views/partials/content-form.blade.php @@ -125,7 +125,7 @@