How to Validate Field Submissions in Drupal

How to Validate Field Submissions in Drupal

As OSTraining member asked us how to validate fields in Drupal 8.

In this particular example, they wanted to make sure that every entry in a text field was unique.

For this tutorial, you will need to download, install and enable the following modules.

Once those modules are enabled, here’s how to set up the validation:

  • Go to Structure > Content types > Manage fields
  • Add a field. In the image below, we’re using a Text (formatted) field:

Add a field in Drupal 8

Once you have saved the field, you can now add validation.

  • Go to Structure > Field validation.
  • Click “Add field validation rules”.
  • Select the entity type and then content type with your field.
  • Click “Create new field validation rule set”.

Add a field validation rule set in Drupal 8

  • Choose the field that you have created.
  • Choose your validation rules.

Add a field validation rule in Drupal 8

  • Add and update the field validation rules set.
  • I would advise you to also run cron on your site.
  • Now you can test the validation rule:

Testing your validated field in Drupal 8

Author

0 0 votes
Article Rating
Subscribe
Notify of
1 Comment
Oldest
Newest
Inline Feedbacks
View all comments
onewomanbiz
onewomanbiz
5 years ago

Hi, I see this article is not recent and perhaps for that reason I am having trouble. 

When you say Go to Structure > Content types > Manage fields… It seems to me, there is a missing piece, I cannot mangae fields until I choose the content type for which I need to manage them. Could you please explain? 

Thank you for your time.

1
0
Would love your thoughts, please comment.x
()
x