0
votes

I'm new to Drupal and I want to build a simple form. I get this error:

Fatal error: Class Drupal\medical\Form\LoginForm contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Drupal\Core\Form\FormInterface::submitForm) in C:\xampp\htdocs\Webdevelopment\Burst\Drupal_Test\modules\medical\src\Form\LoginForm.php on line 8

Here's the code:

<?php

namespace Drupal\medical\Form;

use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Form\FormBase;

class LoginForm extends FormBase {

public function getFormId(){
    return 'medical_login';
}

public function buildForm(array $form, FormStateInterface $form_state) {
    $form['username'] = array(
        '#title' => t('Username'),
        '#type' => 'textfield',
        '#required' => TRUE,
      );

      $form['password'] = array(
          '#title' => t('Password'),
          '#type' => 'password',
          '#required' => TRUE,
        );

      $form['submit'] = array(
        '#type' => 'submit',
        '#value' => 'Login',
      );

}

}

What does this error mean exactly and how do I fix this?

Thanks :)

1

1 Answers

1
votes

In the FormBase there are abstract methods which needs to implemented in child class i.e LoginForm. These are validate and submit methods ( in your case it is submitForm). write these methods in your LoginForm and this error will go