2

I'm trying to create a form that will only allow a maximum of 40 users to complete. After the form hits 40 entries, I would like to hide the fields and show a message (ie. "This course has reached it's capacity and is now closed")

I've tried using FreeForms total_results in an {If} statement, but I can't seem to get it working.

Any Thoughts? Is it possible to do this? Thanks in advance!

{exp:freeform:entries 
                    form_name="camp_registration"
                }

                    {if freeform:no_results}
                        {exp:freeform:form
                            form_name="camp_registration"
                            required="first_name|last_name|date_of_birth|email"
                            }
                            test
                            <div class="form-group">
                                <label>{freeform:label:email} {if freeform:error:email}<span class="error"> - Required</span>{/if}</label><br />
                                {freeform:field:email attr:class="form-control"}
                            </div>

                            <div class="form-group">
                                <button type="submit" class="btn btn-primary">Register</button>
                            </div>
                        {/exp:freeform:form}
                    {/if}


                    {if freeform:count == 1}

                        {if freeform:total_results < 40} /* I'm pretty sure this is where there's a problem */

                            {exp:freeform:form
                                form_name="camp_registration"
                                required="first_name|last_name|date_of_birth|email"
                             }

                                <div class="form-group">
                                    <label>{freeform:label:email} {if freeform:error:email}<span class="error"> - Required</span>{/if}</label><br />
                                    {freeform:field:email attr:class="form-control"}
                                </div>

                                <div class="form-group">
                                    <button type="submit" class="btn btn-primary">Register</button>
                                </div>

                            {/exp:freeform:form}

                        {/if}

                        {if freeform:total_results >= 40}
                            <p>Sorry, maximum form entries allowed reached.</p>
                        {/if}

                    {/if}

                {/exp:freeform:entries}
1
  • Have you tried the query module to perform a count of entries in that form? Looking at the Freeform docs it doesn't appear that free:total_results is a valid variable – CreateSean Apr 3 '14 at 20:41
3

Wrap your {exp:freeform:form} with an {exp:freeform:entries} tag pair and use conditionals to determine if there are more than less than 40 entries for the form. If there are less, present the form, if not, show a message:

{exp:freeform:entries /* your other parameters */}

  {if freeform:no_results}
     {exp:freeform:form /* your other parameters */}
        // Your form code. This will show up if there are no form entries yet.
     {/exp:freeform:form}
  {/if}

  {if freeform:count == 1}

    {if freeform:total_results < 40}
       {exp:freeform:form /* your other parameters */}
          // Your form code
       {/exp:freeform:form}
    {/if}

    {if freeform:total_results >= 40}
       <p>Sorry, maximum form entries allowed reached.</p>
    {/if}

  {/if}

{/exp:freeform:entries}

The {if freeform:count == 1} conditional is to prevent the {exp:freeform:entries} tag from looping and displaying the same content multiple times.

3
  • This is a better solution than the one I posted. – CreateSean Apr 4 '14 at 12:55
  • Thanks to both of you. Unfortunately, I can't seem to get this to work. I can't get anything but a blank page. I think it's breaking when it hits freeform:total_results. I've updated the code in my original post. Any thoughts? – Mark Dodgson Apr 4 '14 at 17:04
  • Try wrapping your freeform:total_results and freeform:count variables with quotes and brackets, since they are in a conditional, i.e. {if '{freeform:count}' == 1} and {if '{freeform:total_results}' < 40} and {if '{freeform:total_results}' >= 40} – Solspace Apr 7 '14 at 5:33
2

What I would try is move your form to an embedded template and in your main template put the following code which is using freeform:entries rather than freeform:form -

{exp:freeform:entries
    form_name="camp_registration"
    limit="100" 
    } 

    {embed="template_group/_formname" form_count="{freeform:total_results}"}

{/exp:freeform:entries} 

Then in your embedded template where you have the conditional you can do a check on the value with {embed:form_count}

1
  • 1
    Actually, to save you from a performance hit, you wouldn't need an embed to have {exp:freeform:form} within {exp:freeform:entries}. I'll post a full example in another response. – Solspace Apr 4 '14 at 6:27

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.