]> _ Git - ccv-wordpress.git/commitdiff
Form builder refactoring + bug fixes. WIP #3383 @12
authorStephen Cameron <stephen@cubedesigners.com>
Mon, 4 May 2020 20:11:06 +0000 (22:11 +0200)
committerStephen Cameron <stephen@cubedesigners.com>
Mon, 4 May 2020 20:11:06 +0000 (22:11 +0200)
20 files changed:
wp-content/mu-plugins/cube/src/Elementor/Widgets/Form.php
wp-content/mu-plugins/cube/src/Forms/Base.php
wp-content/mu-plugins/cube/src/Forms/Builder/Field.php [new file with mode: 0644]
wp-content/mu-plugins/cube/src/Forms/Builder/Fields/Binary.php [new file with mode: 0644]
wp-content/mu-plugins/cube/src/Forms/Builder/Fields/Checkbox.php [new file with mode: 0644]
wp-content/mu-plugins/cube/src/Forms/Builder/Fields/Date.php [new file with mode: 0644]
wp-content/mu-plugins/cube/src/Forms/Builder/Fields/Email.php [new file with mode: 0644]
wp-content/mu-plugins/cube/src/Forms/Builder/Fields/Multi.php [new file with mode: 0644]
wp-content/mu-plugins/cube/src/Forms/Builder/Fields/Radio.php [new file with mode: 0644]
wp-content/mu-plugins/cube/src/Forms/Builder/Fields/Select.php [new file with mode: 0644]
wp-content/mu-plugins/cube/src/Forms/Builder/Fields/Text.php [new file with mode: 0644]
wp-content/mu-plugins/cube/src/Forms/Builder/Fields/Textarea.php [new file with mode: 0644]
wp-content/mu-plugins/cube/src/Forms/Builder/Form.php [new file with mode: 0644]
wp-content/mu-plugins/cube/src/Forms/Consultation.php
wp-content/mu-plugins/cube/src/Forms/Contact.php
wp-content/mu-plugins/cube/src/Forms/Training.php
wp-content/themes/CCV/resources/assets/styles/components/forms.styl
wp-content/themes/CCV/resources/views/forms/consultation.blade.php
wp-content/themes/CCV/resources/views/forms/contact.blade.php
wp-content/themes/CCV/resources/views/forms/training.blade.php

index ab75ec11bf111754f6693e1737d4f745327ebfdd..48e5d35dc5dd080e28095aaa614453500de06257 100644 (file)
@@ -119,7 +119,14 @@ class Form extends _Base {
             /* @var $form BaseForm */
             $form = new $forms[$form_name];
             $form->init();
-            echo view("forms.common.wrapper", compact('form', 'form_name', 'config'));
+
+            $view_data = [
+                'form' => $form->builder,
+                'form_name' => $form_name,
+                'config' => $config,
+            ];
+
+            echo view("forms.common.wrapper", $view_data);
         }
 
         echo '';
index 694fbd773f1a23abfb982b5c509a095844fe9f8d..c8671e49b62842451b8b18c6267ef9a64398cbd1 100644 (file)
@@ -2,35 +2,28 @@
 
 namespace Cube\Forms;
 
+use Cube\Forms\Builder\Form as FormBuilder;
 use function Roots\asset;
 use function Roots\view;
 
 class Base
 {
-    private $action_name = 'cube_forms_process'; // Name of the AJAX action
-    private $destination = 'ccv@ccv-montpellier.fr'; // Default, can be overridden
+    protected $action_name = 'cube_forms_process'; // Name of the AJAX action
+    protected $destination = 'ccv@ccv-montpellier.fr'; // Default, can be overridden
 
-    private $forms = [ // All available forms
+    protected $forms = [ // All available forms
         'consultation' => Consultation::class,
         'training' => Training::class,
         'contact' => Contact::class,
     ];
 
-    private $fields = [];
-    private $config;
-    private $data;
+    protected $fields = [];
+    protected $config;
+    protected $data;
 
-    public $form_title = '';
+    protected $form_title;
 
-    // Field types
-    const BINARY = 'binary';
-    const CHECKBOX = 'checkbox';
-    const DATE = 'date';
-    const EMAIL = 'email';
-    const RADIO = 'radio';
-    const SELECT = 'select';
-    const TEXT = 'text';
-    const TEXTAREA = 'textarea';
+    public $builder;
 
     // Early setup called by Init.php in mu-plugin to register
     // This is separated from init() so we can set up hooks for every request
@@ -46,8 +39,15 @@ class Base
     }
 
     public function init() {
-        $this->register_scripts();
+
         $this->register_fields();
+
+        // Only register the scripts and instantiate HTML builder if this is a non-AJAX request
+        if (!wp_doing_ajax()) {
+            $this->register_scripts();
+
+            $this->builder = new FormBuilder($this->get_fields());
+        }
     }
 
     public function register_scripts() {
@@ -169,7 +169,7 @@ class Base
         // Load the form and process it...
         /* @var $form Base */
         $form = new $this->forms[$form_name];
-        $form->register_fields();
+        $form->init();
         $form->data = $this->get_form_data();
         $form->config = $config;
         $form->set_destination($config['destination']);
@@ -192,13 +192,15 @@ class Base
         $content_type = 'text/html';
         $charset      = get_bloginfo('charset');
         $headers[]    = sprintf('Content-Type: %s; charset=%s', $content_type, $charset);
-        $headers[]    = sprintf('From: %s', $from);
+
+        //TODO: Set up SMTP delivery via CCV's server if we want to change the from address. Attempting to set this results in messages never arriving (starting 30/04/20)
+        //$headers[]    = sprintf('From: %s', $from);
 
         // Gather filled fields into label/value pairs
         foreach ($this->fields as $field_name => $field) {
             // TODO: handle file upload fields - should it be removed from HTML and just attached? Or include the filename reference?
-            if ($value = $this->data($field_name)) {
-                $data[$field['title']] = $value;
+            if ($value = $this->get_data($field_name)) {
+                $data[$field->get_title()] = $value;
             }
         }
 
@@ -228,7 +230,7 @@ class Base
 
     public function post_process() {}
 
-    public function data($name, $default = null) {
+    public function get_data($name, $default = null) {
         if (isset($this->data[$name])) {
             return $this->data[$name];
         }
@@ -236,263 +238,6 @@ class Base
         return $default;
     }
 
-
-    /**
-     * Output field HTML
-     * @param $name
-     * @param array $settings
-     * @return mixed
-     */
-    public function field($name, $settings = []) {
-
-        $field = $this->get_field($name);
-        if (!$field) return false;
-
-        $default_settings = [
-            'class' => '',
-            'title_class' => '',
-            'input_class' => '',
-            'show_title' => true,
-            'show_labels' => true,
-            'show_icon' => true,
-            'placeholder' => $field['title'],
-            'field_before' => '',
-            'field_after' => '',
-            'validation' => '',
-        ];
-        $settings = array_merge($default_settings, $settings);
-
-        // Set up default validation that can be overridden by setting validation field
-        if ($field['required'] && empty($settings['validation'])) {
-            $settings['validation'] = 'required'; // Default but could also be set with other ParsleyJS attributes
-        }
-
-        $res = '';
-
-        if ($settings['show_title']) {
-            $res .= $this->title($name, $settings);
-        }
-
-        // Special input styling for checkbox / radio fields
-        if (in_array($field['type'], [self::BINARY, self::CHECKBOX, self::RADIO])) {
-            $settings['input_class'] .= ' custom-checkbox';
-        }
-
-        if (method_exists($this, $field['type'])) {
-            $res .= '<div class="form-field-input form-field-'. $field['type'] .' '. $settings['input_class'] .'">';
-            $res .= $settings['field_before'];
-            $res .= $this->{$field['type']}($name, $settings);
-            $res .= $settings['field_after'];
-            $res .= '</div>';
-        } else {
-            $res .= 'Unrecognised field: '. $field['type'];
-        }
-
-        return '<div class="form-field '. $settings['class'] .'">'. $res .'</div>';
-    }
-
-    /**
-     * Generate field title
-     * @param $name
-     * @param $settings
-     * @return bool|string
-     */
-    public function title($name, $settings = []) {
-
-        $title_class = $settings['title_class'] ?? '';
-
-        $field = $this->get_field($name);
-        if (!$field) return false;
-
-        return '<div class="form-field-title '. $title_class .'">'. $field['title'] .'</div>';
-    }
-
-    /**
-     * Generate a radio or checkbox input
-     * @param $name
-     * @param $settings
-     * @param string $type
-     * @return string
-     */
-    public function radio_or_checkbox($name, $settings, $type = 'radio') {
-
-        // Options can be overridden
-        $options = isset($settings['options']) ? $settings['options'] : $this->fields[$name]['options'];
-        $input_name = ($type == 'checkbox') ? $name.'[]' : $name;
-
-        $res = '';
-
-        foreach ($options as $option) {
-            $res .= '<label title="'. $option .'">';
-            $res .= '<input type="'. $type .'" name="'. $input_name .'" value="'. $option .'" '. $settings['validation'] .'>';
-
-            if (isset($settings['show_labels']) && $settings['show_labels']) {
-                $res .= '<span class="form-label">'. $option .'</span>';
-            }
-
-            $res .= '</label>';
-        }
-        return $res;
-
-    }
-
-
-    /**
-     * Radio input fields
-     * @param $name
-     * @param $settings
-     * @return string
-     */
-    public function radio($name, $settings = []) {
-        return $this->radio_or_checkbox($name, $settings, 'radio');
-    }
-
-    /**
-     * Checkbox input fields
-     * @param $name
-     * @param $settings
-     * @return string
-     */
-    public function checkbox($name, $settings = []) {
-        return $this->radio_or_checkbox($name, $settings, 'checkbox');
-    }
-
-    /**
-     * Date picker field
-     * @param $name
-     * @param $settings
-     * @return string
-     */
-    public function date($name, $settings = []) {
-        wp_enqueue_style('cube-flatpickr-css');
-        wp_enqueue_script('flatpickr');
-
-        $flatpickr_defaults = [
-            'wrap' => true,
-            'altInput' => true,
-            'altFormat' => 'd/m/Y', // Format shown to user (https://flatpickr.js.org/formatting/)
-            'dateFormat' => 'Y-m-d', // Format returned to the input field
-        ];
-
-        if (!isset($settings['flatpickr'])) $settings['flatpickr'] = [];
-        $flatpickr = array_merge($flatpickr_defaults, $settings['flatpickr']);
-
-        // Load localisation if available
-        if (function_exists('pll_current_language')) {
-            $locale = pll_current_language();
-            $locale_handle = "flatpickr-locale-$locale";
-
-            if (wp_script_is($locale_handle, 'registered')) {
-                wp_enqueue_script($locale_handle);
-                $flatpickr['locale'] = $locale;
-            }
-        }
-
-        // Finally, enqueue the trigger
-        wp_enqueue_script('cube-flatpickr');
-
-        $res  = '<div data-flatpickr="'. esc_attr(json_encode($flatpickr)) .'" class="flex">';
-        $res .= '<input type="date" placeholder="'. $settings['placeholder'] .'" name="'. $name .'" data-input '. $settings['validation'] .'>';
-
-        if ($settings['show_icon']) {
-            $res .= '<img src="' . asset('images/calendar.svg') . '" class="ml-2 mr-6 cursor-pointer" data-toggle>';
-        }
-
-        $res .= '</div>';
-
-        return $res;
-    }
-
-    /**
-     * Binary yes/no field
-     * @param $name
-     * @param $settings
-     * @return string
-     */
-    public function binary($name, $settings = []) {
-
-        $settings['options'] = [
-            __('Oui', 'ccv'),
-            __('Non', 'ccv'),
-        ];
-
-        return $this->radio_or_checkbox($name, $settings, 'radio');
-    }
-
-    /**
-     * Textarea field
-     * @param $name
-     * @param $settings
-     * @return string
-     */
-    public function textarea($name, $settings = []) {
-        return '<textarea name="'. $name .'" '. $settings['validation'] .'></textarea>';
-    }
-
-    /**
-     * Text input field with placeholder
-     * @param $name
-     * @param $settings
-     * @return string
-     */
-    public function text($name, $settings = []) {
-        return '<input type="text" name="'. $name .'" placeholder="'. $settings['placeholder'] .'" '. $settings['validation'] .'>';
-    }
-
-    /**
-     * E-mail input field with placeholder
-     * @param $name
-     * @param $settings
-     * @return string
-     */
-    public function email($name, $settings = []) {
-        return '<input type="email" name="'. $name .'" placeholder="'. $settings['placeholder'] .'" '. $settings['validation'] .'>';
-    }
-
-    /**
-     * Select box
-     * @param $name
-     * @param $settings
-     * @return string
-     */
-    public function select($name, $settings = []) {
-
-        $options = isset($settings['options']) ? $settings['options'] : $this->fields[$name]['options'];
-
-        // Placeholder can be used to set first element if it is passed as an array
-        if (is_array($settings['placeholder'])) {
-            $options = $settings['placeholder'] + $options; // Prepend to options
-        }
-
-        $res  = '<select name="'. $name .'" '. $settings['validation'] .'>';
-        foreach ($options as $value => $label) {
-            $res .= '<option value="'. $value .'">'. $label .'</option>';
-        }
-        $res .= '</select>';
-
-        return $res;
-    }
-
-
-    /**
-     * HTML (submit) button
-     * @param string $text Button label
-     * @param array $settings
-     * @return string
-     */
-    public function button($text, $settings = []) {
-        $default_settings = [
-            'type' => 'submit',
-            'class' => 'btn',
-            'loading_text' => '',
-        ];
-
-        $settings = array_merge($default_settings, $settings);
-
-        return '<button type="'. $settings['type'] .'" class="'. $settings['class'] .'" data-loading-text="'. $settings['loading_text'] .'">'. $text .'</button>';
-    }
-
-
     public function get_destination() {
         return $this->destination;
     }
@@ -503,45 +248,14 @@ class Base
         }
     }
 
-    /**
-     * Set multiple fields at once
-     * @param array $fields
-     */
-    public function set_fields($fields) {
-        $this->fields = $fields;
-    }
-
-    /**
-     * Get all fields
-     * @return array
-     */
-    public function get_fields() {
-        return $this->fields;
-    }
-
-    /**
-     * Get the field names
-     * @return array
-     */
-    public function get_field_keys() {
-        return array_keys($this->fields);
-    }
+    public function add_fields($fields) {
 
-    /**
-     * Add a single field
-     * @param $name
-     * @param $title
-     * @param $type
-     * @param array $options
-     * @param bool $required
-     */
-    public function add_field($name, $title, $type, $options = [], $required = true) {
-        $this->fields[$name]['title'] = $title;
-        $this->fields[$name]['type'] = $type;
-        $this->fields[$name]['required'] = $required;
+        if (!is_array($fields)) {
+            $fields[] = $fields;
+        }
 
-        if (!empty($options)) {
-            $this->set_field_options($name, $options);
+        foreach ($fields as $field) {
+            $this->fields[$field->get_name()] = $field;
         }
     }
 
@@ -564,40 +278,11 @@ class Base
     }
 
     /**
-     * Set the options for a field
-     * @param string $name
-     * @param array $options
-     */
-    public function set_field_options($name, $options) {
-        if ($this->exists($name)) {
-            $this->fields[$name]['options'] = $options;
-        }
-    }
-
-    /**
-     * Get the options for a field
-     * @param string $name
+     * Get all fields
      * @return array
      */
-    public function get_field_options($name) {
-        if ($this->exists($name) && isset($this->fields[$name]['options'])) {
-            return $this->fields[$name]['options'];
-        }
-
-        return [];
-    }
-
-    /**
-     * Helper function to print template code for all fields
-     * @return string
-     */
-    public function generate_code() {
-        $res  = "<pre>AVAILABLE FIELDS:\n\n";
-        foreach ($this->get_field_keys() as $key) {
-            $res .= "{!! \$form->field('$key') !!}\n";
-        }
-        $res .= '</pre>';
-        return $res;
+    public function get_fields() {
+        return $this->fields;
     }
 
 }
diff --git a/wp-content/mu-plugins/cube/src/Forms/Builder/Field.php b/wp-content/mu-plugins/cube/src/Forms/Builder/Field.php
new file mode 100644 (file)
index 0000000..d3d8e28
--- /dev/null
@@ -0,0 +1,113 @@
+<?php
+
+namespace Cube\Forms\Builder;
+
+class Field
+{
+    protected $name;
+    protected $type;
+    protected $title;
+    protected $options = [];
+    protected $settings = [];
+    protected $required = true;
+
+    /**
+     * Field constructor.
+     * @param string $type
+     * @param string $name
+     * @param string $title
+     */
+    public function __construct($type, $name, $title = '') {
+        $this->type = strtolower($type);
+        $this->name($name);
+        $this->title($title);
+    }
+
+    // Allow dynamic chaining with sub-classes - eg. Text::field('test')->title('My title')
+    public static function field($name, $title = '') {
+        // The class name is the type
+        $type = explode('\\', static::class);
+        $type = array_pop($type);
+        return new static($type, $name, $title);
+    }
+
+    public function render($settings) {
+        return ''; // Sub-classes are responsible for output
+    }
+
+    //===================
+
+    public function get_type() {
+        return $this->type;
+    }
+
+    /**
+     * @return string
+     */
+    public function get_name(): string {
+        return $this->name;
+    }
+
+    /**
+     * Set field name
+     * @param string $name
+     * @return Field
+     */
+    public function name($name): self {
+        $this->name = $name;
+        return $this;
+    }
+
+    /**
+     * @return string
+     */
+    public function get_title() {
+        return $this->title;
+    }
+
+    /**
+     * Set field title
+     * @param string $title
+     * @return Field
+     */
+    public function title($title): self {
+        $this->title = $title;
+        return $this;
+    }
+
+
+
+    /**
+     * @return array
+     */
+    public function get_options(): array {
+        return $this->options;
+    }
+
+    /**
+     * Set field options
+     * @param array $options
+     * @return Field
+     */
+    public function options(array $options): self {
+        $this->options = $options;
+        return $this;
+    }
+
+    /**
+     * @return bool
+     */
+    public function is_required(): bool {
+        return $this->required;
+    }
+
+    /**
+     * Set required flag
+     * @param bool $required
+     * @return Field
+     */
+    public function required(bool $required = true): self {
+        $this->required = $required;
+        return $this;
+    }
+}
diff --git a/wp-content/mu-plugins/cube/src/Forms/Builder/Fields/Binary.php b/wp-content/mu-plugins/cube/src/Forms/Builder/Fields/Binary.php
new file mode 100644 (file)
index 0000000..3cfc603
--- /dev/null
@@ -0,0 +1,19 @@
+<?php
+
+namespace Cube\Forms\Builder\Fields;
+
+// Yes / No control
+class Binary extends Radio
+{
+    public function render($settings) {
+
+        $settings['options'] = [
+            __('Oui', 'cube'),
+            __('Non', 'cube'),
+        ];
+
+        return parent::render($settings);
+    }
+
+
+}
diff --git a/wp-content/mu-plugins/cube/src/Forms/Builder/Fields/Checkbox.php b/wp-content/mu-plugins/cube/src/Forms/Builder/Fields/Checkbox.php
new file mode 100644 (file)
index 0000000..c4e1a01
--- /dev/null
@@ -0,0 +1,15 @@
+<?php
+
+namespace Cube\Forms\Builder\Fields;
+
+class Checkbox extends Multi
+{
+    protected $input_type = 'checkbox';
+
+    public function render($settings) {
+
+        $settings['input_class'] .= ' custom-checkbox';
+
+        return parent::render($settings);
+    }
+}
diff --git a/wp-content/mu-plugins/cube/src/Forms/Builder/Fields/Date.php b/wp-content/mu-plugins/cube/src/Forms/Builder/Fields/Date.php
new file mode 100644 (file)
index 0000000..59b792a
--- /dev/null
@@ -0,0 +1,50 @@
+<?php
+
+namespace Cube\Forms\Builder\Fields;
+
+use Cube\Forms\Builder\Field;
+use function Roots\asset;
+
+class Date extends Field
+{
+    public function render($settings) {
+
+        wp_enqueue_style('cube-flatpickr-css');
+        wp_enqueue_script('flatpickr');
+
+        $flatpickr_defaults = [
+            'wrap' => true,
+            'altInput' => true,
+            'altFormat' => 'd/m/Y', // Format shown to user (https://flatpickr.js.org/formatting/)
+            'dateFormat' => 'Y-m-d', // Format returned to the input field
+        ];
+
+        if (!isset($settings['flatpickr'])) $settings['flatpickr'] = [];
+        $flatpickr = array_merge($flatpickr_defaults, $settings['flatpickr']);
+
+        // Load localisation if available
+        if (function_exists('pll_current_language')) {
+            $locale = pll_current_language();
+            $locale_handle = "flatpickr-locale-$locale";
+
+            if (wp_script_is($locale_handle, 'registered')) {
+                wp_enqueue_script($locale_handle);
+                $flatpickr['locale'] = $locale;
+            }
+        }
+
+        // Finally, enqueue the trigger
+        wp_enqueue_script('cube-flatpickr');
+
+        $res  = '<div data-flatpickr="'. esc_attr(json_encode($flatpickr)) .'" class="flex">';
+        $res .= '<input type="date" placeholder="'. $settings['placeholder'] .'" name="'. $this->get_name() .'" data-input '. $settings['validation'] .'>';
+
+        if ($settings['show_icon']) {
+            $res .= '<img src="' . asset('images/calendar.svg') . '" class="ml-2 mr-6 cursor-pointer" data-toggle>';
+        }
+
+        $res .= '</div>';
+
+        return $res;
+    }
+}
diff --git a/wp-content/mu-plugins/cube/src/Forms/Builder/Fields/Email.php b/wp-content/mu-plugins/cube/src/Forms/Builder/Fields/Email.php
new file mode 100644 (file)
index 0000000..203238e
--- /dev/null
@@ -0,0 +1,12 @@
+<?php
+
+namespace Cube\Forms\Builder\Fields;
+
+use Cube\Forms\Builder\Field;
+
+class Email extends Field
+{
+    public function render($settings) {
+        return '<input type="email" name="'. $this->get_name() .'" placeholder="'. $settings['placeholder'] .'" '. $settings['validation'] .'>';
+    }
+}
diff --git a/wp-content/mu-plugins/cube/src/Forms/Builder/Fields/Multi.php b/wp-content/mu-plugins/cube/src/Forms/Builder/Fields/Multi.php
new file mode 100644 (file)
index 0000000..9ad4169
--- /dev/null
@@ -0,0 +1,35 @@
+<?php
+
+namespace Cube\Forms\Builder\Fields;
+
+use Cube\Forms\Builder\Field;
+
+// Multi input - shared for radios and checkboxes
+class Multi extends Field
+{
+    protected $input_type = 'checkbox'; // Default, possible options: checkbox | radio
+
+    public function render($settings) {
+
+        // Options can be overridden
+        $options = isset($settings['options']) ? $settings['options'] : $this->get_options();
+        $input_name = ($this->input_type == 'checkbox') ? $this->get_name().'[]' : $this->get_name();
+
+        $res = '';
+
+        foreach ($options as $option) {
+            $res .= '<label title="'. $option .'">';
+            $res .= '<input type="'. $this->input_type .'" name="'. $input_name .'" value="'. $option .'" '. $settings['validation'] .'>';
+
+            if (isset($settings['show_labels']) && $settings['show_labels']) {
+                $res .= '<span class="form-label">'. $option .'</span>';
+            }
+
+            $res .= '</label>';
+        }
+        return $res;
+
+
+
+    }
+}
diff --git a/wp-content/mu-plugins/cube/src/Forms/Builder/Fields/Radio.php b/wp-content/mu-plugins/cube/src/Forms/Builder/Fields/Radio.php
new file mode 100644 (file)
index 0000000..6ef6c7b
--- /dev/null
@@ -0,0 +1,8 @@
+<?php
+
+namespace Cube\Forms\Builder\Fields;
+
+class Radio extends Multi
+{
+    protected $input_type = 'radio';
+}
diff --git a/wp-content/mu-plugins/cube/src/Forms/Builder/Fields/Select.php b/wp-content/mu-plugins/cube/src/Forms/Builder/Fields/Select.php
new file mode 100644 (file)
index 0000000..879198d
--- /dev/null
@@ -0,0 +1,26 @@
+<?php
+
+namespace Cube\Forms\Builder\Fields;
+
+use Cube\Forms\Builder\Field;
+
+class Select extends Field
+{
+    public function render($settings) {
+
+        $options = isset($settings['options']) ? $settings['options'] : $this->get_options();
+
+        // Placeholder can be used to set first element if it is passed as an array
+        if (is_array($settings['placeholder'])) {
+            $options = $settings['placeholder'] + $options; // Prepend to options
+        }
+
+        $res  = '<select name="'. $this->get_name() .'" '. $settings['validation'] .'>';
+        foreach ($options as $value => $label) {
+            $res .= '<option value="'. $value .'">'. $label .'</option>';
+        }
+        $res .= '</select>';
+
+        return $res;
+    }
+}
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
new file mode 100644 (file)
index 0000000..be9a979
--- /dev/null
@@ -0,0 +1,12 @@
+<?php
+
+namespace Cube\Forms\Builder\Fields;
+
+use Cube\Forms\Builder\Field;
+
+class Text extends Field
+{
+    public function render($settings) {
+        return '<input type="text" name="'. $this->get_name() .'" placeholder="'. $settings['placeholder'] .'" '. $settings['validation'] .'>';
+    }
+}
diff --git a/wp-content/mu-plugins/cube/src/Forms/Builder/Fields/Textarea.php b/wp-content/mu-plugins/cube/src/Forms/Builder/Fields/Textarea.php
new file mode 100644 (file)
index 0000000..b540e19
--- /dev/null
@@ -0,0 +1,12 @@
+<?php
+
+namespace Cube\Forms\Builder\Fields;
+
+use Cube\Forms\Builder\Field;
+
+class Textarea extends Field
+{
+    public function render($settings) {
+        return '<textarea name="'. $this->get_name() .'" '. $settings['validation'] .'></textarea>';
+    }
+}
diff --git a/wp-content/mu-plugins/cube/src/Forms/Builder/Form.php b/wp-content/mu-plugins/cube/src/Forms/Builder/Form.php
new file mode 100644 (file)
index 0000000..d26a4c4
--- /dev/null
@@ -0,0 +1,129 @@
+<?php
+
+namespace Cube\Forms\Builder;
+
+use Cube\Forms\Base;
+
+// HTML Form Builder
+class Form extends Base
+{
+    public function __construct($fields) {
+        $this->fields = $fields;
+    }
+
+    public function process_settings($field, $settings = []) {
+
+        $default_settings = [
+            'class' => '',
+            'title_class' => '',
+            'input_class' => '',
+            'show_title' => true,
+            'show_labels' => true,
+            'show_icon' => true,
+            'placeholder' => $field->get_title(),
+            'field_before' => '',
+            'field_after' => '',
+            'validation' => '',
+        ];
+
+        return array_merge($default_settings, $settings);
+    }
+
+    /**
+     * Output field HTML
+     * @param $name
+     * @param array $settings
+     * @return mixed
+     */
+    public function field($name, $settings = []) {
+
+        /* @var $field Field */
+        $field = $this->get_field($name);
+        if (!$field) return false;
+
+        $settings = $this->process_settings($field, $settings);
+
+        // Set up default validation that can be overridden by setting validation field
+        if ($field->is_required() && empty($settings['validation'])) {
+            $settings['validation'] = 'required'; // Default but could also be set with other ParsleyJS attributes
+        }
+
+        // Special styling class for checkbox / radio fields
+        if (in_array($field->get_type(), ['binary', 'checkbox', 'radio'])) {
+            $settings['input_class'] .= ' custom-checkbox';
+        }
+
+        $res = '';
+
+        if ($settings['show_title']) {
+            $res .= $this->title($name, $settings);
+        }
+
+        $res .= '<div class="form-field-input form-field-'. $field->get_type() .' '. $settings['input_class'] .'">';
+        $res .= $settings['field_before'];
+        $res .= $field->render($settings);
+        $res .= $settings['field_after'];
+        $res .= '</div>';
+
+        return '<div class="form-field '. $settings['class'] .'">'. $res .'</div>';
+    }
+
+    /**
+     * Generate field title
+     * @param $name
+     * @param $settings
+     * @return bool|string
+     */
+    public function title($name, $settings = []) {
+
+        $title_class = $settings['title_class'] ?? '';
+
+        $field = $this->get_field($name);
+        if (!$field) return false;
+
+        return '<div class="form-field-title '. $title_class .'">'. $field->get_title() .'</div>';
+    }
+
+
+    /**
+     * HTML (submit) button
+     * @param string $text Button label
+     * @param array $settings
+     * @return string
+     */
+    public function button($text, $settings = []) {
+        $default_settings = [
+            'type' => 'submit',
+            'class' => 'btn',
+            'loading_text' => '',
+        ];
+
+        $settings = array_merge($default_settings, $settings);
+
+        return '<button type="'. $settings['type'] .'" class="'. $settings['class'] .'" data-loading-text="'. $settings['loading_text'] .'">'. $text .'</button>';
+    }
+
+
+    /**
+     * Get the field names
+     * @return array
+     */
+    public function get_field_keys() {
+        return array_keys($this->fields);
+    }
+
+    /**
+     * Helper function to print template code for all fields
+     * @return string
+     */
+    public function generate_code() {
+        $res  = "<pre>AVAILABLE FIELDS:\n\n";
+        foreach ($this->get_field_keys() as $key) {
+            $res .= "{!! \$form->field('$key') !!}\n";
+        }
+        $res .= '</pre>';
+        return $res;
+    }
+
+
+}
index bbff867be372306f1cd6a163b0f6875d6375ccfa..d30008fb55aaec3d1042edd5ae2ede793ad7c680 100644 (file)
@@ -2,6 +2,15 @@
 
 namespace Cube\Forms;
 
+use Cube\Forms\Builder\Fields\Binary;
+use Cube\Forms\Builder\Fields\Checkbox;
+use Cube\Forms\Builder\Fields\Date;
+use Cube\Forms\Builder\Fields\Email;
+use Cube\Forms\Builder\Fields\Radio;
+use Cube\Forms\Builder\Fields\Select;
+use Cube\Forms\Builder\Fields\Text;
+use Cube\Forms\Builder\Fields\Textarea;
+
 use function Roots\asset;
 
 class Consultation extends Base
@@ -22,101 +31,96 @@ class Consultation extends Base
 
     function register_fields() {
 
-        parent::register_fields();
-
-        //== SYMPTOMS
-        $this->add_field('main-problem', __('Problème principal', 'ccv'), self::RADIO,
-            [
-                __('Cervicales', 'ccv'),
-                __('Lombaires', 'ccv'),
-                __('Scoliose', 'ccv'),
-            ]
-        );
-
-        $this->add_field('date-first-symptoms', __('Date des premiers symptômes :', 'ccv'), self::DATE);
-
-        $this->add_field('date-pain-since', __('Douleurs permanentes depuis (le cas échéant) :', 'ccv'), self::DATE, [], false);
-
-        $this->add_field('pain-arms-legs', __('Avez-vous des douleurs dans les bras ou les jambes (sciatiques, cruralgies, névralgies) ?', 'ccv'), self::BINARY);
-
-        $this->add_field('pain-arms-legs-detail', __('Si oui, cochez les membres concernés :', 'ccv'), self::CHECKBOX,
-            [
-                __('Haut du bras gauche', 'ccv'),
-                __('Haut du bras droit', 'ccv'),
-                __('Avant-bras gauche', 'ccv'),
-                __('Avant-bras droit', 'ccv'),
-                __('Haut de la jambe gauche', 'ccv'),
-                __('Haut de la jambe droite', 'ccv'),
-                __('Bas de la jambe gauche', 'ccv'),
-                __('Bas de la jambe droite', 'ccv'),
-            ],
-            false // Set not required
-        );
-
-        $this->add_field('main-pain', __('La douleur principale est-elle ?', 'ccv'), self::RADIO,
-            [
-                __('Dans la colonne', 'ccv'),
-                __('Dans les membres', 'ccv'),
-                __('Les deux', 'ccv'),
-            ]
-        );
-
-        $this->add_field('tingling-numbness', __('Avez-vous des fourmillements ou une sensation d’engourdissement dans un des membres ? ', 'ccv'), self::BINARY);
-
-        $this->add_field('tingling-numbness-date', __('Si oui depuis quand ?', 'ccv'), self::DATE, [], false);
-
-        $this->add_field('strength-loss', __('Avez-vous une perte de force importante dans un des membres ?', 'ccv'), self::BINARY);
-
-        $this->add_field('strength-loss-date', __('Si oui depuis quand ?', 'ccv'), self::DATE, [], false);
-
-        //=== TREATMENTS
-        $this->add_field('medication', __('Indiquez ici les médicaments que vous avez pris pour vos douleurs (le cas échéant)', 'ccv'), self::TEXTAREA, [], false);
-
-        $this->add_field('kine-osteo', __('Kinésithérapie ou ostéopathie', 'ccv'), self::BINARY);
-        $this->add_field('corset', __('Corset ou ceinture lombaire', 'ccv'), self::BINARY);
-        $this->add_field('hospitalisation', __('Séjour en hospitalisation', 'ccv'), self::BINARY);
-        $this->add_field('infiltration', __('Infiltration ou thermocoagulation', 'ccv'), self::BINARY);
-
-        $this->add_field('surgeries', __('Indiquez ici vos précédentes chirurgies de la colonne et leurs dates (le cas échéant)', 'ccv'), self::TEXTAREA, [], false);
-
-        //=== IMAGERY
-        $this->add_field('imagery-type', __('Imagerie', 'ccv'), null, [], false); // This is a special case and will be output manually so only using this for the e-mail label
-        $this->add_field('imagery-online', __('Images en ligne', 'ccv'), self::TEXTAREA, [], false); // Again, a manually handled field
-        $this->add_field('imagery-posted', __('Images envoyé par courrier', 'ccv'), self::CHECKBOX, [], false);
-
-        //=== PERSONAL INFORMATION
-        $this->add_field('last-name', _x('Nom', 'Nom de famille', 'ccv'), self::TEXT);
-        $this->add_field('first-name', __('Prénom', 'ccv'), self::TEXT);
-        $this->add_field('profession', __('Profession', 'ccv'), self::TEXT);
-        $this->add_field('city', __('Ville', 'ccv'), self::TEXT);
-        $this->add_field('country', __('Pays', 'ccv'), self::TEXT);
-        $this->add_field('phone', __('Tel', 'ccv'), self::TEXT);
-        $this->add_field('email', __('Email', 'ccv'), self::EMAIL);
-        $this->add_field('sex', __('Sexe', 'ccv'), self::RADIO, [_x('M', 'Sexe (M)', 'ccv'), _x('F', 'Sexe (F)', 'ccv')]);
-        $this->add_field('age', __('Âge :', 'ccv'), self::TEXT);
-        $this->add_field('message', __('Avez vous un message (ou une demande) spécifique à nous formuler ?', 'ccv'), self::TEXTAREA, [], false);
-
-        // Special field: if a surgeon is selected, their e-mail address will be override the default delivery address
-        $this->add_field('surgeon', __('Chirurgien spécifique'), self::SELECT,
-            [
-                // TODO: Add proper e-mail addresses here once we have them
-                'Dr Guilhaume GENESTE' => 'xxxxx@ccv-montpellier.fr',
-                'Dr Grégory EDGARD-ROSA' => 'xxxxx@ccv-montpellier.fr',
-                'Dr Martin GRAU ORTIZ' => 'xxxxx@ccv-montpellier.fr',
-                'Dr Caroline HIRSH' => 'xxxxx@ccv-montpellier.fr',
-            ],
-            false // Set not required
-        );
+        $this->add_fields([
+
+            //== SYMPTOMS
+            Radio::field('main-problem', __('Problème principal', 'ccv'))
+                ->options([
+                    __('Cervicales', 'ccv'),
+                    __('Lombaires', 'ccv'),
+                    __('Scoliose', 'ccv'),
+                ]),
+
+            Date::field('date-first-symptoms', __('Date des premiers symptômes :', 'ccv')),
+
+            Date::field('date-pain-since', __('Douleurs permanentes depuis (le cas échéant) :', 'ccv'))->required(false),
+
+            Binary::field('pain-arms-legs', __('Avez-vous des douleurs dans les bras ou les jambes (sciatiques, cruralgies, névralgies) ?', 'ccv')),
+
+            Checkbox::field('pain-arms-legs-detail', __('Si oui, cochez les membres concernés :', 'ccv'))
+                ->required(false)
+                ->options([
+                    __('Haut du bras gauche', 'ccv'),
+                    __('Haut du bras droit', 'ccv'),
+                    __('Avant-bras gauche', 'ccv'),
+                    __('Avant-bras droit', 'ccv'),
+                    __('Haut de la jambe gauche', 'ccv'),
+                    __('Haut de la jambe droite', 'ccv'),
+                    __('Bas de la jambe gauche', 'ccv'),
+                    __('Bas de la jambe droite', 'ccv'),
+                ]),
+
+            Radio::field('main-pain', __('La douleur principale est-elle ?', 'ccv'))
+                ->options([
+                    __('Dans la colonne', 'ccv'),
+                    __('Dans les membres', 'ccv'),
+                    __('Les deux', 'ccv'),
+                ]),
+
+            Binary::field('tingling-numbness', __('Avez-vous des fourmillements ou une sensation d’engourdissement dans un des membres ? ', 'ccv')),
+            Date::field('tingling-numbness-date', __('Si oui depuis quand ?', 'ccv'))->required(false),
+
+            Binary::field('strength-loss', __('Avez-vous une perte de force importante dans un des membres ?', 'ccv')),
+            Date::field('strength-loss-date', __('Si oui depuis quand ?', 'ccv'))->required(false),
+
+            //=== TREATMENTS
+            Textarea::field('medication', __('Indiquez ici les médicaments que vous avez pris pour vos douleurs (le cas échéant)', 'ccv'))->required(false),
+            Binary::field('kine-osteo', __('Kinésithérapie ou ostéopathie', 'ccv')),
+            Binary::field('corset', __('Corset ou ceinture lombaire', 'ccv')),
+            Binary::field('hospitalisation', __('Séjour en hospitalisation', 'ccv')),
+            Binary::field('infiltration', __('Infiltration ou thermocoagulation', 'ccv')),
+            Textarea::field('surgeries', __('Indiquez ici vos précédentes chirurgies de la colonne et leurs dates (le cas échéant)', 'ccv'))->required(false),
+
+            //=== IMAGERY
+            // This is a special case and will be output manually so only using this for the e-mail label
+            Radio::field('imagery-type', __('Imagerie', 'ccv'))->required(false),
+            Textarea::field('imagery-online', __('Images en ligne', 'ccv'))->required(false), // Again, a manually handled field
+            Checkbox::field('imagery-posted', __('Images envoyé par courrier', 'ccv'))->required(false),
+
+            //=== PERSONAL INFORMATION
+            Text::field('last-name', _x('Nom', 'Nom de famille', 'ccv')),
+            Text::field('first-name', __('Prénom', 'ccv')),
+            Text::field('profession', __('Profession', 'ccv')),
+            Text::field('city', __('Ville', 'ccv')),
+            Text::field('country', __('Pays', 'ccv')),
+            Text::field('phone', __('Tel', 'ccv')),
+            Email::field('email', __('Email', 'ccv')),
+            Radio::field('sex', __('Sexe', 'ccv'))
+                ->options([
+                    _x('M', 'Sexe (M)', 'ccv'),
+                    _x('F', 'Sexe (F)', 'ccv'),
+                ]),
+            Text::field('age', __('Âge :', 'ccv')),
+            Textarea::field('message', __('Avez vous un message (ou une demande) spécifique à nous formuler ?', 'ccv'))->required(false),
+
+            // Special field: if a surgeon is selected, their e-mail address will be override the default delivery address
+            Select::field('surgeon', __('Chirurgien spécifique'))
+                ->required(false)
+                ->options([
+                    // TODO: Add proper e-mail addresses here once we have them
+                    'Dr Guilhaume GENESTE' => 'xxxxx@ccv-montpellier.fr',
+                    'Dr Grégory EDGARD-ROSA' => 'xxxxx@ccv-montpellier.fr',
+                    'Dr Martin GRAU ORTIZ' => 'xxxxx@ccv-montpellier.fr',
+                    'Dr Caroline HIRSH' => 'xxxxx@ccv-montpellier.fr',
+                ]),
+        ]);
     }
 
     public function pre_process() {
-
         // If a surgeon is selected, send the form directly to them
-        $surgeons = $this->get_field_options('surgeon');
-        if (!empty($this->data('surgeon')) && array_key_exists($this->data('surgeon'), $surgeons)) {
-            $this->set_destination($surgeons[$this->data('surgeon')]);
+        $surgeons = $this->get_field('surgeon')->get_options();
+        if (!empty($this->get_data('surgeon')) && array_key_exists($this->get_data('surgeon'), $surgeons)) {
+            $this->set_destination($surgeons[$this->get_data('surgeon')]);
         }
     }
-
-
 }
index 9ba13acf356d42b0f3950fd22a8c6553e81f2be0..89c5212160bfda35a3d4396bc2cdb2c6bfc59cb6 100644 (file)
@@ -2,6 +2,8 @@
 
 namespace Cube\Forms;
 
+use Cube\Forms\Builder\Fields\Text;
+
 class Contact extends Base
 {
     public function __construct() {
@@ -10,10 +12,11 @@ class Contact extends Base
 
     function register_fields() {
 
-        parent::register_fields();
+        $this->add_fields([
+            Text::field('last-name', _x('Nom', 'Nom de famille', 'ccv')),
+            Text::field('first-name', __('Prénom', 'ccv')),
+            Text::field('phone', __('Téléphone', 'ccv'))
+        ]);
 
-        $this->add_field('last-name', _x('Nom', 'Nom de famille', 'ccv'), self::TEXT);
-        $this->add_field('first-name', __('Prénom', 'ccv'), self::TEXT);
-        $this->add_field('phone', __('Téléphone', 'ccv'), self::TEXT);
     }
 }
index 49ae6157dabe22c183b612a2fb2b3afa947f4798..167f9af193f0a2c48e6139d9cd3b8c611df3c822 100644 (file)
@@ -2,66 +2,63 @@
 
 namespace Cube\Forms;
 
+use Cube\Forms\Builder\Fields\Date;
+use Cube\Forms\Builder\Fields\Email;
+use Cube\Forms\Builder\Fields\Radio;
+use Cube\Forms\Builder\Fields\Text;
+
 class Training extends Base
 {
     public function __construct() {
         $this->form_title = __('Demande de formation', 'ccv');
     }
 
-    public function register_scripts() {
-        parent::register_scripts();
-    }
-
-
     function register_fields() {
 
-        parent::register_fields();
+        $this->add_fields([
 
-        //== IDENTITY
-        $this->add_field('last-name', _x('Nom', 'Nom de famille', 'ccv'), self::TEXT);
-        $this->add_field('first-name', __('Prénom', 'ccv'), self::TEXT);
-        $this->add_field('birth-date', __('Date de naissance', 'ccv'), self::DATE);
-        $this->add_field('phone', __('Tel', 'ccv'), self::TEXT);
-        $this->add_field('email', __('Mail', 'ccv'), self::EMAIL);
-        $this->add_field('country-residence', __('Pays de résidence', 'ccv'), self::TEXT);
-        $this->add_field('country-training', __('Pays de formation chirurgicale', 'ccv'), self::TEXT);
+            //== IDENTITY
+            Text::field('last-name', _x('Nom', 'Nom de famille', 'ccv')),
+            Text::field('first-name', __('Prénom', 'ccv')),
+            Date::field('birth-date', __('Date de naissance', 'ccv')),
+            Text::field('phone', __('Tel', 'ccv')),
+            Email::field('email', __('Mail', 'ccv')),
+            Text::field('country-residence', __('Pays de résidence', 'ccv')),
+            Text::field('country-training', __('Pays de formation chirurgicale', 'ccv')),
+            Radio::field('speciality', __('Spécialité chirurgicale', 'ccv'))
+                ->options([
+                    __('Neurochirurgien', 'ccv'),
+                    __('Chirurgien orthopédiste avec chirurgie du rachis exclusif', 'ccv'),
+                    __('Chirurgien orthopédiste généraliste', 'ccv'),
+                ]),
+            Radio::field('status', __('Statut', 'ccv'))
+                ->options([
+                    __('Etudiant (interne, fellow)', 'ccv'),
+                    __('Chirurgien en activité', 'ccv'),
+                ]),
 
-        $this->add_field('speciality', __('Spécialité chirurgicale', 'ccv'), self::RADIO,
-            [
-                __('Neurochirurgien', 'ccv'),
-                __('Chirurgien orthopédiste avec chirurgie du rachis exclusif', 'ccv'),
-                __('Chirurgien orthopédiste généraliste', 'ccv'),
-            ]
-        );
 
-        $this->add_field('status', __('Statut', 'ccv'), self::RADIO,
-            [
-                __('Etudiant (interne, fellow)', 'ccv'),
-                __('Chirurgien en activité', 'ccv'),
-            ]
-        );
+            //== AREA OF INTERVENTION
+            Radio::field('experience-lumbar-anterior', __("Quel niveau d'expertise avez-vous dans ce domaine ?", 'ccv'))
+                ->options([
+                    __("Pas d'expérience", 'ccv'),
+                    __('Moins de 20 chirurgies', 'ccv'),
+                    __('Entre 20 et 100', 'ccv'),
+                    __('Plus de 100 chirurgies', 'ccv'),
+                ]),
+            Radio::field('experience-scoliosis', __("Quel niveau d’expertise avez-vous dans la chirurgie de la scoliose ?", 'ccv'))
+                ->options([
+                    __("Pas d'expérience", 'ccv'),
+                    __('Moins de 20 chirurgies', 'ccv'),
+                    __('Entre 20 et 100', 'ccv'),
+                    __('Plus de 100 chirurgies', 'ccv'),
+                ]),
 
-        //== AREA OF INTERVENTION
-        $this->add_field('experience-lumbar-anterior', __("Quel niveau d'expertise avez-vous dans ce domaine ?", 'ccv'), self::RADIO,
-            [
-                __("Pas d'expérience", 'ccv'),
-                __('Moins de 20 chirurgies', 'ccv'),
-                __('Entre 20 et 100', 'ccv'),
-                __('Plus de 100 chirurgies', 'ccv'),
-            ]
-        );
 
-        $this->add_field('experience-scoliosis', __("Quel niveau d’expertise avez-vous dans la chirurgie de la scoliose ?", 'ccv'), self::RADIO,
-            [
-                __("Pas d'expérience", 'ccv'),
-                __('Moins de 20 chirurgies', 'ccv'),
-                __('Entre 20 et 100', 'ccv'),
-                __('Plus de 100 chirurgies', 'ccv'),
-            ]
-        );
+            //== TYPE OF TRAINING
+            // Since this question has a complex layout, the options are set in the template (formation.blade.php)
+            Radio::field('training-type', __('Par quel type de formation au CCV Montpellier êtes-vous intéressé ?', 'ccv'))
 
-        //== TYPE OF TRAINING
-        // Since this question has a complex layout, the options are set in the template (formation.blade.php)
-        $this->add_field('training-type', __('Par quel type de formation au CCV Montpellier êtes-vous intéressé ?', 'ccv'), self::RADIO, null);
+        ]);
     }
 }
index f87cdc5fedf613edb4b956ded66381787bb1296e..2a5693aa38d4a2daa86f04a81722fa985fd74c47 100644 (file)
@@ -75,15 +75,15 @@ input[type="submit"]
 
   .form-label:before,
   .form-label-reversed:after
-      content: ''
-      display: inline-block
-      vertical-align: middle
-      width: 24px
-      height: @width
-      border: 1px solid #000
-      background-color: #fff
-      box-shadow: inset 0 0 0 4px #fff // Inner border for checkbox
-      cursor: pointer
+    content: ''
+    display: inline-block
+    vertical-align: middle
+    width: 24px
+    height: @width
+    border: 1px solid #000
+    background-color: #fff
+    box-shadow: inset 0 0 0 4px #fff // Inner border for checkbox
+    cursor: pointer
 
   .form-label:before
     margin-right: 0.5em
@@ -92,7 +92,7 @@ input[type="submit"]
 
   input:checked ~ .form-label:before,
   input:checked ~ .form-label-reversed:after
-      @apply bg-pink
+    @apply bg-pink
 
   input
     position: absolute
@@ -108,8 +108,8 @@ input[type="submit"]
   margin-bottom: 0.75em
 
 .form-field-input
-  > *:not(:last-child)
-    margin-right: 1.5em
+  > *:not(:first-child)
+    margin-left: 1.5em
 
   label
     white-space: nowrap // Ensure text stays beside input control
@@ -158,6 +158,7 @@ input[type="submit"]
   left: 0
   bottom: -2em
   padding: 0
+  margin-left: 0 !important
   font-size: 0.7em
   white-space: nowrap
 
index 300b0c55b091fbecc5672f5fda8be90c32ffe626..a81b6e2a5fa2b98d8498d042a3a1f4dbe66621b8 100644 (file)
@@ -1,5 +1,5 @@
 {{-- CONSULTATION FORM --}}
-@php /* @var $form \Cube\Forms\Consultation */ @endphp
+@php /* @var $form \Cube\Forms\Builder\Form */ @endphp
 
 {{-- SYMPTOMS --}}
 <div class="bg-light text-block-body py-2v pl-4v pr-3v xs:px-2v">
@@ -46,7 +46,7 @@
             <div class="pain-areas">
               <img src="@asset('images/consultation-body-outline.svg')" class="consultation-body-outline-image">
 
-              @foreach ($form->get_field_options('pain-arms-legs-detail') as $option)
+              @foreach ($form->get_field('pain-arms-legs-detail')->get_options() as $option)
                 <label title="{{ $option }}">
                   <input type="checkbox" name="pain-arms-legs-detail[]" value="{{ $option }}">
                   <span class="form-label">{{-- No label here but the element is needed so custom checkboxes work --}}</span>
           </label>
         </div>
         {{ __("ou je souhaite l'envoyer à un chirurgien spécifique :", 'ccv') }}
-        {!! $form->field('surgeon', [
-          'class' => 'mt-4',
-          'show_title' => false,
+
+        @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.
-          'options' => array_combine(array_keys($form->get_field_options('surgeon')), array_keys($form->get_field_options('surgeon'))),
+          $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
           ]
index 4b94f0546fca098b8d8224c0dd070466786c36d6..c33236dbd91d441730be57e16bc17f8cba1c7c6c 100644 (file)
@@ -1,5 +1,5 @@
 {{-- CONTACT FORM --}}
-@php /* @var $form \Cube\Forms\Contact */ @endphp
+@php /* @var $form \Cube\Forms\Builder\Form */ @endphp
 
 <div class="spaced">
   {!! $form->field('last-name', ['show_title' => false]) !!}
index 170bdeab3fb226180889ccbfe9a0d1870ed1fd7b..eb0ee713e25332c685e6edc0f79826e5366edf8f 100644 (file)
@@ -1,5 +1,5 @@
 {{-- TRAINING FORM --}}
-@php /* @var $form \Cube\Forms\Training */ @endphp
+@php /* @var $form \Cube\Forms\Builder\Form */ @endphp
 
 {{-- IDENTITY --}}
 <div class="bg-light text-block-body py-2v pl-4v pr-3v xs:px-2v">