form.html.twig 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. {% if form is null %}
  2. {% set form = grav.session.getFlashObject('form') %}
  3. {% endif %}
  4. {% include 'partials/form-messages.html.twig' %}
  5. {% set scope = scope ?: 'data.' %}
  6. {% set multipart = '' %}
  7. {% set method = form.method|upper|default('POST') %}
  8. {% set client_side_validation = form.client_side_validation is not null ? form.client_side_validation : config.plugins.form.client_side_validation|default(true) %}
  9. {% set inline_errors = form.inline_errors is not null ? form.inline_errors : config.plugins.form.inline_errors(false) %}
  10. {% for field in form.fields %}
  11. {% if (method == 'POST' and field.type == 'file') %}
  12. {% set multipart = ' enctype="multipart/form-data"' %}
  13. {% endif %}
  14. {% endfor %}
  15. {% set action = form.action ? base_url ~ form.action : base_url ~ page.route ~ uri.params %}
  16. {% if (action == base_url_relative) %}
  17. {% set action = base_url_relative ~ '/' ~ page.slug %}
  18. {% endif %}
  19. <form name="{{ form.name }}"
  20. action="{{ action | trim('/', 'right') }}"
  21. method="{{ method }}"{{ multipart }}
  22. {% if form.id %}id="{{ form.id }}"{% endif %}
  23. {% block form_classes %}
  24. class="{{ form_outer_classes }} {{ form.classes }}"
  25. {% endblock %}
  26. {% if form.novalidate %}novalidate{% endif %}
  27. >
  28. {% block inner_markup_fields_start %}{% endblock %}
  29. {% for field in form.fields %}
  30. {% if field.type == 'file' %}
  31. {% do assets.addJs('plugin://form/assets/form.min.js') %}
  32. {% endif %}
  33. {% set value = form.value(field.name) %}
  34. {% include "forms/fields/#{field.type}/#{field.type}.html.twig" ignore missing %}
  35. {% endfor %}
  36. {% include "forms/fields/formname/formname.html.twig" %}
  37. {% block inner_markup_fields_end %}{% endblock %}
  38. {% block inner_markup_buttons_start %}
  39. <div class="{{ form_button_outer_classes ?: 'buttons'}}">
  40. {% endblock %}
  41. {% for button in form.buttons %}
  42. {% if button.outerclasses is defined %}<div class=" {{ button.outerclasses }}">{% endif %}
  43. {% if button.url %}
  44. <a href="{{ button.url starts with 'http' ? button.url : url(button.url) }}">
  45. {% endif %}
  46. <button
  47. {% if button.id %}id="{{ button.id }}"{% endif %}
  48. {% block button_classes %}
  49. class="{{ form_button_classes ?: 'button' }} {{ button.classes }}"
  50. {% endblock %}
  51. {% if button.disabled %}disabled="disabled"{% endif %}
  52. type="{{ button.type|default('submit') }}"
  53. {% if button.task %}
  54. name="task" value="{{ button.task }}"
  55. {% endif %}
  56. >
  57. {{ button.value|t|default('Submit') }}
  58. </button>
  59. {% if button.url %}
  60. </a>
  61. {% endif %}
  62. {% if button.outerclasses is defined %}</div>{% endif %}
  63. {% endfor %}
  64. {% block inner_markup_buttons_end %}
  65. </div>
  66. {% endblock %}
  67. {% include 'forms/fields/uniqueid/uniqueid.html.twig' %}
  68. {{ nonce_field('form', 'form-nonce')|raw }}
  69. </form>
  70. {% if config.forms.dropzone.enabled %}
  71. <div id="dropzone-template" style="display:none;">
  72. {% include 'forms/dropzone/template.html.twig' %}
  73. </div>
  74. {% endif %}