Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added safe_email filter for email field #480

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 %}