# Creating custom form error handling

**URL:** <https://www.ruby-forum.com/t/creating-custom-form-error-handling/187228>\
**Category:** Rails\
**Created:** [April 20, 2010, 7:34am UTC](https://www.ruby-forum.com/t/creating-custom-form-error-handling/187228 "2010-04-20T07:34:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dkam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e5b9ba/32.png) [@dkam](https://www.ruby-forum.com/u/dkam)\
**Post date:** [April 20, 2010, 7:34am UTC](https://www.ruby-forum.com/t/creating-custom-form-error-handling/187228/1 "2010-04-20T07:34:02Z")

</div>

im tracking events which have a few groups of related data, like  
dates, times and tickets.  
the issue im running into is when multiple forms make up one piece of  
validation:  
ex: if this is checked, these fields need to be present and one needs  
to be greater than the other…  
if one of these things is not right, id like to change two label type  
fields where these input fields are grouped.

im guessing i cannot use the built in validation tools to handle these  
errors, since it only seems to want to highlight the label and field  
in question.  
are there any good examples of how to group input elements and handle  
errors so that one error highlights all relevant fields?

for example, if the end time is before the start time, i want to  
highlight my time form elements along with error message

---

<div class="post-metadata">

**Author:** ![dkam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e5b9ba/32.png) [@dkam](https://www.ruby-forum.com/u/dkam)\
**Post date:** [April 20, 2010, 3:05pm UTC](https://www.ruby-forum.com/t/creating-custom-form-error-handling/187228/2 "2010-04-20T15:05:57Z")

</div>

You’ll need to write a custom validation, I think, if you want to  
highlight more than 1 field for a given condition.

if end\_time \< start\_time  
errors.add :start\_time, ‘your message here’  
errors.add :start\_time, ‘your message here’  
end

What I have never tried is to hightlight a field without a message so,  
in your case, having a unique error message (and no extra empty lines  
in the messages section) but 2 fields highlighted at the same time.
