Upgrade Your Drupal Skills

We trained 1,000+ Drupal Developers over the last decade.

See Advanced Courses NAH, I know Enough

How to Add Existing Fields to a Custom Form

Parent Feed: 

We had a custom user registration form for use in our Commerce checkout account registration workflow that allows users to register during the checkout process. We wanted to add additional fields to the custom registration form but adding the fields to the standard user entity would not display the fields in our custom form as its fields are all created manually in the custom form.

In Drupal 7 we would use the field_attach_form() function but it is removed in Drupal 8. Below is how we achieved this in Drupal 8/9.

Original Post: 

About Drupal Sun

Drupal Sun is an Evolving Web project. It allows you to:

  • Do full-text search on all the articles in Drupal Planet (thanks to Apache Solr)
  • Facet based on tags, author, or feed
  • Flip through articles quickly (with j/k or arrow keys) to find what you're interested in
  • View the entire article text inline, or in the context of the site where it was created

See the blog post at Evolving Web

Evolving Web