<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def form_invalid(self, form):
 """ Handles an invalid form. """

        messages.error(self.request, form.errors[NON_FIELD_ERRORS])
        return redirect(
            reverse(
                'forum_conversation:topic',
                kwargs={
                    'forum_slug': self.object.topic.forum.slug,
                    'forum_pk': self.object.topic.forum.pk,
                    'slug': self.object.topic.slug,
                    'pk': self.object.topic.pk
                },
            ),
        )