3

I'm trying to customize the markup of an email select field in Sprout Forms, however, when I customize the markup with Custom HTML, as specified in the documentation, it outputs the actual value rather than purging it to hide them from spam bots. I just need to know what I should include in the options to purge these. Here is the code I've been using.

{% set recipient = form.getField('emailRecipient') %}  
<select name="fields[{{ recipient.handle }}]">
  {% for option in recipient.settings.options %}
  <option value="{{ option.value }}" {% if option.value == value.value %}selected{% endif %}>{{ option.label }}</option>
  {% endfor %}
</select>

Any help would be greatly appreciated!

Thanks.

  • This is likely a bug. I've added it to our list to look into and will update this thread once it's fixed. – Ben Parizek Sep 3 '16 at 7:48
2

This feature has been added in Sprout Fields v2.1.0

You can now use the Email Select field via custom HTML and obfuscate email addresses. I've added an example in the docs:

{% set contact = craft.sproutForms.form('contact') %}

{% set emailSelectField = contact.getField('emailSelect') %}

<select name="fields[{{ emailSelectField.handle }}]">

  {% set value = contact is defined ? contact.emailSelect.value : null %}

  {% set options = craft.sproutFields.obfuscateEmailAddresses(emailSelectField.settings.options, value) %}

  {% for option in options %}

    {% if value != "" %}
      {% set selected = (option.selected == 1) ? true : false %}
    {% else %}
      {% set selected = (option.default == 1) ? true : false %}
    {% endif %}

    <option value="{{ option.value }}" {% if selected %}selected{% endif %}>{{ option.label }}</option>

  {% endfor %}

</select>
  • I've somehow put myself in a situation where I have to pass the $option index in for the value attribute. I used loop.index0. It's better in our case because our option.values aren't unique, but option.value didn't work for us. – ponies Nov 3 '19 at 8:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.