$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() {}
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 '<input type="'.$type.'" name="'. $this->get_name() .'" placeholder="'. $settings['placeholder'] .'" '. $settings['validation'] . ' '.$attr.'>';
'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
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),
]);
}
$this->set_destination($surgeons[$this->get_data('surgeon')]);
}
}
+
+ if($this->form_title === "appointment") {
+ $this->remove_field('surgeon');
+ }
}
}
// 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?
$('.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() {
<div class="custom-checkbox my-1v">
<label>
- <input type="checkbox" name="condition" required>
+ <input type="checkbox" name="imagery-condition" value="Oui" required>
<span
class="form-label text-lg font-normal leading-tight">{{ __('J\'ai bien noté que mon dossier ne pourra être étudié si je fournis pas une IRM de moins de 6 mois', 'ccv') }}</span>
<span class="text-sm font-normal" style="margin-left: 33px;">{{ __('En cas de pathologies de scoliose, envoyez-nous impérativement une radiographie du rachis en totalité, en place de l\'IRM.', 'cvv') }}</span>
{!! $form->field('message', ['class' => 'mt-6', 'title_class' => 'font-light']) !!}
@if($form_name !== "appointment")
- <div class="mt-4">
- <div class="custom-checkbox mb-1">
- <label>
- <input type="checkbox" name="send-to-team" value="{{ __('Oui', 'ccv') }}" checked class="ml-2">
- <span class="form-label-reversed">{{ __("J'envoie ma demande à l'équipe du CCV", 'ccv') }}</span>
- </label>
+ <div class="mt-4">
+ <div class="custom-checkbox mb-1">
+ <label>
+ <input type="checkbox" name="send-to-team" value="{{ __('Oui', 'ccv') }}" checked class="ml-2">
+ <span class="form-label-reversed">{{ __("J'envoie ma demande à l'équipe du CCV", 'ccv') }}</span>
+ </label>
+ </div>
+ {{ __("ou je souhaite l'envoyer à un chirurgien spécifique :", 'ccv') }}
+
+ @php
+ // The options for this field contains the e-mail address as the value but we don't want to expose that here
+ // so we override options with a new array made up of just their names as both the key and value.
+ // Once the form is processed, this will be used to look up the e-mail address.
+ $surgeons = array_keys($form->get_field('surgeon')->get_options());
+ $surgeons_options = array_combine($surgeons, $surgeons);
+ @endphp
+ {!! $form->field('surgeon', [
+ 'class' => 'mt-4',
+ 'show_title' => false,
+ 'options' => $surgeons_options,
+ 'placeholder' => [
+ '' => __('Sélectionner', 'ccv') // First select option
+ ]
+ ]) !!}
</div>
- {{ __("ou je souhaite l'envoyer à un chirurgien spécifique :", 'ccv') }}
-
- @php
- // The options for this field contains the e-mail address as the value but we don't want to expose that here
- // so we override options with a new array made up of just their names as both the key and value.
- // Once the form is processed, this will be used to look up the e-mail address.
- $surgeons = array_keys($form->get_field('surgeon')->get_options());
- $surgeons_options = array_combine($surgeons, $surgeons);
- @endphp
- {!! $form->field('surgeon', [
- 'class' => 'mt-4',
- 'show_title' => false,
- 'options' => $surgeons_options,
- 'placeholder' => [
- '' => __('Sélectionner', 'ccv') // First select option
- ]
- ]) !!}
- </div>
@endif
</div>
</form>
<script>
(function ($) {
+ $('[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();
+ });
+
// Clicking browse triggers the file form. It opens the dialog to capture images or browse files
$('#phone-image-browse').on('click touchend', function () {
$('#phone-file-upload-field').click();