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.
$pane_form['subscription_payment_type'] = [ '#type' => 'radios', '#title_display' => 'hidden', '#options' => [ 'digital' => $this->t('Digital signature'), 'paper' => $this->t('Paper form'), ], 'digital' => [ '#description' => $this->t('(E-identification or BankID)'), ], '#default_value' => 'digital', ];
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.
Styling a Webform is more or less like styling any other ordinary HTML form. Often you would like to change the style of the submit button and replace it with an image via code in your Drupal website. Although this is extremely easy it might cause the button to stop working, forcing it to reload and fail to show the confirmation message.
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 :-