1

Is it possible to add type attributes to inputs when using the FreeForm Composer Templates? If I hard-code a form I can add type="email" or type="tel" but cant see any way to do this when using Composer.

Additionally if I add attr:required="required" to {freeform:field:{composer:field_name} the output is required="required" which although correct for xhtml, is not correct for HTML5 - should simply be 'required'. Is there a way to alter this?

2

It's also possible to use an add-on like CE String to circumvent this:

{exp:ce_str:ing replace='required="required"|required'}
{exp:freeform:form}
{freeform:field:myfield
 attr:required="required"
}
{/exp:freeform:form}
{/exp:ce_str:ing}

will output

<input type="text" name="myfield" value="" id="freeform_myfield" required>
| improve this answer | |
1

You would have to first create a custom Composer Template (can be done from the CP or using the {exp:freeform:composer} tag as a tag pair with Composer Template code inside), and manually create/hand-code your field output when your custom field is called. For example, based on the default Composer Template code, there is this conditional:

...
{if:else}
    <p>{composer:field_output}</p>
{/if}

Which you could change to

...
{if:else}
    {if composer:field_name == "my_email_field"}
        <input type="email" name="my_email_field" placeholder="Enter email" />
    {if:else} 
        <p>{composer:field_output}</p>
    {/if}
{/if}

The other alternative is to use javascript to change the type="" when the form is loaded from your template. Again, you would need to target the fields that you want to change.

Finally, you could file a Feature Request, for some setting in the CP for example, under the specific add-on category here: http://support.solspace.com/support/discussions. It'll also give other users the option to vote up the feature request, and help us prioritize features to add in upcoming versions of this add-on.

As for your sub-question, there's not much that can be done with required="required", short of using javascript to format it the way you want. The other option could be to file a Feature Request for this as well.

| improve this answer | |
  • Thanks for the answer although would I be right in thinking this is only going to work as long as the user creates fields using the same field name? I've added a feature request as suggested. – Damien Buckley Jul 31 '14 at 23:16
  • Yes, the field name would need to match. You could use a conditional for the field_type_ instead, but that wouldn't be very specific when using generic fields such as an input field. – Solspace Aug 1 '14 at 4:55
  • Forgot to mention one more alternative: create a custom fieldtype for Freeform. Maybe overkill in some cases such as this, but still an option. Dev docs can be found here: solspace.com/docs/freeform/fieldtype_development – Solspace Aug 1 '14 at 4:56
1

A similar approach if using EE3, you can use Streeng and wrap this around form code:

{exp:streeng find='required="required"' replace="required"}
    {exp:freeform:form
        attr:required="required"
    }
        ...
    {/exp:freeform:form}
{/exp:streeng}
| improve this answer | |

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.