1

I wanted to build a commerce website using craft 3 cms. And I wanted to create parent registration form so each parent will have an account to use on the site. Then after they sign in I want them to be able to add their children.

Is this possible to do using craft 3 cms. The only thing I found is user registration form on the documentation.

If there is a blog of documentation to integrate this feature using craft 3 cms or is there anything I missed so far.

Kirubel
  • 1,461
  • 1
  • 14
  • 33

1 Answers1

1

It depends how complex your parent - child relation will be. The best solution would be is to write a custom plugin or module for that, with records and rules, some controllers ...etc

My solution would be the following

  1. Allow public registration

  2. Create two user groups:

    • Parent
    • Child
  3. Set the default user group to Parent

  4. Make sure the user group Parent has the permission: Assign User Groups -> Assign users to "Child" checked

  5. Create a field group with one field in it:

    • parentId > number (more precisely int)
  6. Assign this field group to the users

  7. Create a front-end user registration form for the parents so they can register.

  8. And then you will need one more form for the parents, so they can register their children.For this, the parents are required to be logged in, otherwise it won't work.

  9. You can check this with

{% if not craft.app.user.isGuest %}

  {# Your child registration form #}

  <input type="hidden" id="parentId" name="parentId" value="{{ craft.app.user.id }}">

  {% else %}

  {# The user is not logged in #}

{% endif %}

This way you can:

  • Differentiate Parent users from children using:

{% set userGroups = craft.app.user.identity.getGroups() %}

  • Get the logged in child's parent user object using:

{% set parent = craft.users().id( craft.app.user.identity.parentId ).one()%}

  • Get the logged in parents children

{% set children = craft.users().parentId( craft.app.user.id ).all() %}

HunWalk
  • 82
  • 3