In this article, we are going to look at building a multistep form in Drupal 8. For brevity, the form will have only two steps in the shape of two completely separate forms. To persist values across these steps, we will use functionality provided by Drupal’s core for storing temporary and private data across multiple requests.
Drupal form_set_error() function provide validation message based field name. So if you have same field name in same page , after the submission you can see both fields are marked as red color(Error class). It validate or show message for right form but it provide error class for all element which are same.
I found a way to solve it. If you render those form using drupal_get_form then you can add one extra line in top to get rid of this problem.
If you use multiple submit button in Drupal from and add ajax call to submit button then you ajax submit button will execute form default validate and submit function. To prevent it from calling those default function you just need to do two following steps.
1) rename my validation function from "myformname_validate" to "myformname_do_validate". This caused my validate function to not be called during the ajax request.
2) attach the "myformname_do_validate" function to my submit button like so:
Sample code in your .module file for Drupal 7 as follow :-