0

In Freeform I use the loop to display all my fields:

{freeform:all_form_fields}
    <dt>
        <label>{freeform:field_label}</label>
    </dt>
    <dd>
        <!-- place holder for ajax errors-->
        <div class="error_message"></div>
        {freeform:field_output}
    </dd>
{/freeform:all_form_fields}

how can I display an asterix beside fields which are required? Form called and required fields displayed like:

{exp:freeform:form
    form:id="ajax_form"
    form:class="form-horizontal"
    form_name="enq_form"
    required="business_name|business_category|contact_person|email_address"
    }
0

You've hard-coded the required fields in the template by including them in the template tag, so why not hard code it in your loop?

<label>
    {freeform:field_label}
    {if freeform:field_name == "business_name" 
        || freeform:field_name == "business_category"
        || freeform:field_name == "contact_person" 
        || freeform:field_name == "email_address"}
        <span class="required">*</span>
    {/if}
</label>

I didn't say it was a great solution! In the docs there's no mention of freeform:field_required variable :(

I'd strongly recommend you use the Composer though - especially as you have the Pro version. It is really great, and you can create a template that is fully flexible for any type of form your editor/admin wants to create. And it has a variable to detect if a field is required. So nothing is hard coded in the template! See an example here, or you want more example code, raise another question.

3
  • I already had the form done in Composer but changed to the Form and Ajax submission as I wanted the form to retain the values when the user made an error. In composer when there was an error the form was blanked.
    – mmc501
    Feb 8 '16 at 12:34
  • Thought you went down the Ajax route to solve that?: expressionengine.stackexchange.com/questions/35474/… - You an still use Ajax with Composer. Feb 8 '16 at 12:39
  • Ah I did - but used the example in the docs on their website which used the standard form - never thought of the Ajax with Composer - that would have been the best solution!
    – mmc501
    Feb 8 '16 at 12:42

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.