Archive for Drupal

Custom validation on existing Drupal form


validationCustom validation on existing Drupal form

Hello folks, How are you doing? Thank you for your comments and queries on other topics I have written. There were queries on custom validation on existing Drupal form. So here is the post for you 🙂

Below is how we add custom validation on existing Drupal form. for example we want to add form validation to user login form, as this form is in Drupal’s core module we are not supposed to hack that module. So we need to create a new custom module say for example my_module. (I am assuming you know Drupal module development or comment below if you want me to write a blog on Drupal module development :))

Ok, so we have a module named my_module. Now we need to implement hook_form_alter to add a custom validation function to validate user login form, below is code snippet to do that.

Above code will look for the function validate_this_form() in your module when the form the user form is submitted.

So, lets implement that function and restrict some login names (Just to know how it works). Lets add if condition in function to check user name and set error message accordingly.

Above function will be executed and set validation error message for the form if username used is ‘sachin’

Below is how the error message gets added through our above function where username ‘sachin’ is checked.

custom validation on existing Drupal form

Please feel free to ask queries in comments or contact me using contact form on this site. I will be happy to help you out. Thank you for reading this post and see you again later with new post. 🙂

Or, please login using google or facebook and create a forum topic to get your query answered in few hours here

Thank you,


Drupal view listing content associated with term ID from URL


If you want to have content listed with taxonomy term id in URL. Below are the things you need to do.

1. Create a view of type block having list of all taxonomy terms and have them a link to some page with term id in it.
2. Create content view of type block and have contextual filter there with “Content: Has taxonomy term ID” click on “Provide default value” and select “Taxonomy term ID from URL”
3. Create a page with some URL Read more


How to change “apply” button text in Drupal Views exposed filters


Below are the things you will need to do to know how to change “apply” button text

1) Open your current themes template.php file

2) append following function in it. Read more