Skip to content

Commit

Permalink
Added safe_email filter for email field
Browse files Browse the repository at this point in the history
Note: This requires grav 1.7.0-rc.18, as safe_email got fixed there:
getgrav/grav@068de42
  • Loading branch information
NicoHood committed Jan 13, 2021
1 parent af87ce0 commit 4cb494e
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions templates/forms/fields/email/email.html.twig
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
{% extends "forms/field.html.twig" %}

{% block input_attributes %}
type="email"
{% if field.multiple in ['on', 'true', 1] %}multiple="multiple"{% endif %}
{% if field.size %}size="{{ field.size }}"{% endif %}
{% if field.minlength is defined or field.validate.min is defined %}minlength="{{ field.minlength | default(field.validate.min) }}"{% endif %}
{% if field.maxlength is defined or field.validate.max is defined %}maxlength="{{ field.maxlength | default(field.validate.max) }}"{% endif %}
{{ parent() }}
{% block global_attributes %}
data-grav-field="{{ field.type }}"
data-grav-disabled="{{ toggleable and toggleableChecked }}"
data-grav-default="{{ (default ? default|json_encode())|safe_email|raw }}"
{% endblock %}

{% block input %}
<div class="{{ layout_form_field_wrapper_classes }} {{ field.size }}">
{% block prepend %}{% endblock prepend %}
{% set input_value = value is iterable ? value|join(',') : value|string %}
<input
name="{{ (scope ~ field.name)|fieldName }}"
value="{{ input_value|safe_email|raw }}"
{% block input_attributes %}
type="email"
{% if field.multiple in ['on', 'true', 1] %}multiple="multiple"{% endif %}
{% if field.size %}size="{{ field.size }}"{% endif %}
{% if field.minlength is defined or field.validate.min is defined %}minlength="{{ field.minlength | default(field.validate.min) }}"{% endif %}
{% if field.maxlength is defined or field.validate.max is defined %}maxlength="{{ field.maxlength | default(field.validate.max) }}"{% endif %}
{{ parent() }}
{% endblock %}
/>
{% block append %}{% endblock append %}
{% if inline_errors and errors %}
<div class="{{ form_field_inline_error_classes }}">
<p class="form-message"><i class="fa fa-exclamation-circle"></i> {{ errors|first|raw }}</p>
</div>
{% endif %}
</div>
{% endblock %}

0 comments on commit 4cb494e

Please sign in to comment.