1

I have implemented an if/else statement and when I add the information to the 'else' part it outputs three duplicates of the same content.

I am calling the if statement to check if the user is signed in here more andless. If they are they will get a booking form which shows up fine and only one of them.

{% for user in craft.users.groups('nomad') %}
{% if user.isCurrent %}
<div class="wrapper">
<form method="post" action="" accept-charset="UTF-8">
    {{ getCsrfInput() }}

    {% for entry in craft.entries.section('studios').search(studio) %}
        <input type="hidden" name="fields[studioEmail]" value="{{ entry.email 
    }}">
    {% endfor %}
    <input type="hidden" name="action" 
    value="amForms/submissions/saveSubmission">
    <input type="hidden" name="handle" value="bookingForm">

    {# Optional: Redirect URL. Will redirect to current page by default. #}
    <input type="hidden" name="redirect" value="booking-form/thank-you">

    {{ craft.amForms.displayAntispam() }}


            <div class="input__wrapper">
                <label for="fields-firstName" class="sr-only">First 
     Name</label>
                <input type="text" id="fields-firstName" 
      name="fields[firstName]" autocomplete="off" placeholder="First Name" 
     value="{{ currentUser.firstName }}">
            </div>

            <div class="input__wrapper">
                <label for="fields-lastName" class="sr-only">Last Name</label>
                <input type="text" id="fields-lastName" 
               name="fields[lastName]" autocomplete="off" placeholder="Last 
               Name" value="{{ currentUser.lastName }}">
            </div>

            <div class="input__wrapper">
                <label for="fields-mobileNumber" class="sr-only">Mobile Number</label>
                <input type="text" id="fields-mobileNumber" name="fields[mobileNumber]" autocomplete="off" placeholder="Mobile Number" value="{{ currentUser.mobileNumber }}">
            </div>

            <div class="input__wrapper">
                <label for="fields-startDate" class="sr-only">Start 
                Date</label>
                <input type="text" id="fields-startDate" 
                name="fields[startDate]" autocomplete="off" placeholder="start 
        Date">
            </div>

            <div class="input__wrapper">
                <label for="fields-endDate" class="sr-only">End Date</label>
                <input type="text" id="fields-endDate" name="fields[endDate]" 
                autocomplete="off" placeholder="End Date">
            </div>

            <div class="input__wrapper">
                <label for="fields-studio" class="sr-only">Studio</label>
                <select name="fields[studio]" id="fields-studio">
                    {% for entry in craft.entries.section('studios').find() %}
                        <option value="{{ entry.title }}"

                        {% if studio == entry.title %}
                                selected="selected"
                        {% endif %}


                        >{{ entry.title }}</option>
                    {% endfor %}
                </select>
            </div>



    <input type="submit" value="Submit">
  </form>
  </div>

Then this is the else statement. I think I might need to add something to the {% else %}. Though I don't see why it would be outputting three duplicates of the same content in the first place.

  {% else %}
  <section class="form__wrapper">
  <div class="content__form_wrapper sign-up_wrapper">
    <h1>Become a Digital Nomad and join the community</h1>
    <p>You need to be a member to rent a desk, it will only take a moment of   
    your and you will be on your way.</p>

    <a href="{{ siteUrl }}users/sign-up" class="">Sign Up</a
</div>
</section>
{% endif %}
{% endfor %}

Thanks for the help :)

4
  • Maybe because there is a loop? It will output the content for each user in the group – Robin Schambach May 5 '18 at 12:11
  • Yea it seems to be pulling in for each 'user', will try to fix it now.. Thanks for the help :) – Zack Reid May 5 '18 at 14:38
  • Why do you even use this loop? It really makes no sense at all – Robin Schambach May 5 '18 at 15:06
  • To be honest I didn't even know this was a loop :/.. I am just trying to display a form if the user is logged in. If they are not it won't show and sign up button will instead.. I thought an if/else statement would be the way todo this? – Zack Reid May 5 '18 at 15:21
1

In Craft there are several so called global variables one of them is the currentUser thus you can check if someone is logged in with

{% if currentUser %} 

{% else %} 

{% endif %} 

You don't need to loop a user array

2

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.