1

I want to add extra fields during user registration. I don't Understand Where I can access to user form and user twig, because I want to validate and reformat the Form.

My background is symfony, and I expect The model if I want to add some properties ( in drupal maybe is entity ) and the twig ( the view Parts ), Instead here I don't know where is the user form.

I'm trying to create the module and use some hook, but I don't know if the right way to customize the form

2

You can go to configuration -> account settings -> manage fields and add your field. then in the settings check it to show in registration form

admin/config/people/accounts/fields
6
  • Thanks, but I want custom fields – monkeyUser Dec 8 '15 at 15:49
  • Why you need custom form if you have everything available in configuration. I would suggest to look at hook_<form_id>_alter in that case and add your field there. – Shabir A. Dec 8 '15 at 15:51
  • Thanks shabir. For Example I Want to Add country with select of country and city ( auto-filter ), and send several email when the user is register... Where I have to implement all these behaviours ? And Where Can i Find the form_id? – monkeyUser Dec 8 '15 at 15:53
  • inspect your element and if there the form id is user-register-form then the hook will be modulename_form_user_register_form_alter($form, &$form_state) – Shabir A. Dec 8 '15 at 16:04
  • do you say this ? api.drupal.org/api/drupal/… ? Where put this code? in my_module.module or mymodule/src/Form/myForm.php ? – monkeyUser Dec 8 '15 at 16:33
0

If you download and install the Address module, it will give you an Address field type you can add to the profile, including dropdown lists for country and region in many countries.

If this doesn't give you what you want, have a look at the Examples module, and in particular at field_example, which will show you how to create your own field type that can be added to the profile (or any other Entity form in Drupal). This is a much better approach than hacking fields onto the form with hook_form_alter, as it uses the power of the Drupal platform and means you are creating a component you can use elsewhere.

Hope this gets you started!

James

1
  • I have an error with address module Address requires the commerceguys/addressing library. – monkeyUser Dec 8 '15 at 16:25
0

The short answer to your question is that Drupal gets its power comes from bringing many different toolsets together. The user registration form is made up of functionalities from many different parts of Drupal's APIs. There is no one place to go to change the working of this form. You can get better help if you ask a number of more specific and focused questions.

You seem to have at least 5 different problems (as elaborated in your comments).

FIELD: You need a field, as @JamesShields said. This can either be a custom field from your custom module, or from the Address module. Installation process for Address requires composer, an is discussed here: https://bojanz.wordpress.com/2015/09/18/d8-composer-definitive-intro/

FIELDS: You need to add the field to the user account settings, as @Shabir said, at admin/config/people/accounts/fields

EMAIL: You need to do something to do with emails, either a) modifying the built in emails at admin/config/people/accounts, b) waiting until March when the Rules module hopes to become usable, or c) sending emails from custom code in response to the user registration. I could not find a code example to help with c), you may have to start a new question for that.

REFORMAT: to reformat the form, you need to find the right twig template. Turning on twig debugging is a good place to start with this. See http://www.zyxware.com/articles/4531/drupal-how-do-i-turn-on-twig-debug-mode-in-drupal-8

VALIDATE: If you require validation beyond what is supported by the available fields already, then you want either the entity validation API or the Form API, from custom code. The examples module is a good reference, or a more basic tutorial from Google.

0

You can also create a new profile by going to structure -> profiletypes and customize fields depending on the profile type if you have distinct profile types.

1
  • I don't find profiletype in /admin/structure – monkeyUser Dec 8 '15 at 15:54

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.