Modified code to implement search form validation