首先自定义一个 Form:
/**
* @file
* Contains \Drupal\resume\Form\WorkForm.
*/
namespace Drupal\resume\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
class workForm extends FormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'resume_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form['employee_name'] = array(
'#type' => 'textfield',
'#title' => t('Employee Name:'),
'#required' => TRUE,
);
$form['employee_mail'] = array(
'#type' => 'email',
'#title' => t('Email ID:'),
'#required' => TRUE,
);
$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => $this->t('Register'),
'#button_type' => 'primary',
);
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
drupal_set_message($this->t('@emp_name ,Your application is being submitted!',
array('@emp_name' => $form_state->getValue('employee_name'))));
}
}