1

I have been testing out my user registration form and get to the following point:

1. User is created

Most of the profile is created, except the firstName and lastName (these are the handles that I am using in the form) are not created.

2. User is not added to default group

Here is my form markup:

<form method="post" accept-charset="UTF-8">
    {{ getCsrfInput() }}

    <input type="hidden" name="action" value="users/saveUser">
    <input type="hidden" name="redirect" value="{{ url('/?status=registrationEmailSent') }}">

    {% macro errorList(errors) %}
        {% if errors %}
            <ul class="errors">
                {% for error in errors %}
                    <li>{{ error }}</li>
                {% endfor %}
            </ul>
        {% endif %}
    {% endmacro %}

    {% from _self import errorList %}

    <h3>Required fields:</h3>

    <h4><label for="firstName">First Name</label></h4>
    <input type="text" id="firstName" name="fields[firstName]" 
        {%- if account is defined %} value="{{ account.firstName }}"{% endif %}>
    {{ account is defined and account ? errorList(account.getErrors('firstName')) }}

    <h4><label for="lastName">Surname</label></h4>
    <input type="text" id="lastName" name="fields[lastName]" 
        {%- if account is defined %} value="{{ account.lastName }}"{% endif %}>
    {{ account is defined and account ? errorList(account.getErrors('lastName')) }}

    <h4><label for="username">Username</label></h4>
    <input id="username" type="text" name="username"
        {%- if account is defined %} value="{{ account.username }}"{% endif -%}>

    {% if account is defined %}
        {{ errorList(account.getErrors('username')) }}
    {% endif %}

    <h4><label for="email">Email</label></h4>
    <input id="email" type="text" name="email"
        {%- if account is defined %} value="{{ account.email }}"{% endif %}>

    {% if account is defined %}
        {{ errorList(account.getErrors('email')) }}
    {% endif %}

    <h4><label for="password">Password</label></h4>
    <input id="password" type="password" name="password">

    {% if account is defined %}
        {{ errorList(account.getErrors('password')) }}
    {% endif %}

    <h3>Optional fields:</h3>
    <p class="instructions">We would appreciate it if you could please provide just a little bit more info about your company.</p>
    <h4><label for="membersCompanyName">Company Name</label></h4>
    <input type="text" id="membersCompanyName" name="fields[membersCompanyName]" 
        {%- if account is defined %} value="{{ account.membersCompanyName }}"{% endif %}>
    {{ account is defined and account ? errorList(account.getErrors('membersCompanyName')) }}

    <h4><label for="membersPosition">Job Title</label></h4>
    <input type="text" id="membersPosition" name="fields[membersPosition]" 
        {%- if account is defined %} value="{{ account.membersPosition }}"{% endif %}>
    {{ account is defined and account ? errorList(account.getErrors('membersPosition')) }}

    <h4><label for="membersPhoneNumber">Telephone no.</label></h4>
    <input type="text" id="membersPhoneNumber" name="fields[membersPhoneNumber]" 
        {%- if account is defined %} value="{{ account.membersPhoneNumber }}"{% endif %}>
    {{ account is defined and account ? errorList(account.getErrors('membersPhoneNumber')) }}

    <h4><label for="membersWebsite">Website</label></h4>
    <input type="text" id="membersWebsite" name="fields[membersWebsite]" 
        {%- if account is defined %} value="{{ account.membersWebsite }}"{% endif %}>
    {{ account is defined and account ? errorList(account.getErrors('membersWebsite')) }}

    <input type="submit" value="Register">
    <p><a href="{{ url('members/login') }}">No, I just want to log in.</a></p>
</form>

Any help would be greatly appreciated.

  • 1
    Have exactly same problem where user is not being added to a group on registration in the front-end. did you work out a solution to this problem? – Cole Henley May 10 '16 at 15:16
1

Somewhere, I came across a thread that Brad had provided a bit of insight about the First & Last name fields. They are kind of "special" is all I can remember.

In any event, the First & Last name fields do not need the fields prepended to them. They can get passed along like this:

<input type="text" id="firstName" name="firstName" class="form-control" 
{%- if account is defined %} value="{{ account.firstName }}"{% endif %}">
{{ account is defined and account ? errorList(account.getErrors('firstName')) }}

...

<input type="text" id="lastName" name="lastName" class="form-control" 
{%- if account is defined %} value="{{ account.lastName }}"{% endif %}">
{{ account is defined and account ? errorList(account.getErrors('lastName')) }}

As for not getting added to your group, have you created a user group for newly registered users? For example, let's say I created a user group called "Public". Then (assuming you are using Craft Pro) Craft will give me the option to choose which user group I want the default user group to be. Are you able to set that?

  • Thanks Damon, The first name and last name now function properly after updating the name attribute to the input. With regards to the user not getting added to the default group 'Registered User' - yes I have Craft Pro, yes the group has been selected as the default group that new users will be added to, but no they are not being added to it. FYI the group is empty currently. Thanks – Adam Menczykowski Jan 4 '16 at 9:57
  • Can anybody chime in as to perhaps why the new user is not getting added to the default group? – Adam Menczykowski Jan 4 '16 at 16:01
  • Update: Disabling 'Verify email addresses?' doesn't alter the behaviour other than the user is created and activated simultaneously. Unfortunately, the user is still not added to the default user group. – Adam Menczykowski Jan 6 '16 at 15:36
  • Probably silly comment, but do you have "allow guest registration" checked? Very strange that the users aren't getting added. When you visit that CP screen, does the drop down reflect the default user group? – Damon Jan 7 '16 at 14:23
  • If you mean 'Allow public registration?' - yes that is checked. And yes the dropdown reflects the default user group 'Registered Users' – Adam Menczykowski Jan 7 '16 at 15:08
0

Answer to the confirmation email and group issue.

I was have the exact same issue but it seems that it was because I was already logged into Craft (as an admin in my case). So try it in a private window or be sure to not be logged in.

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.