Forms use the Submit element for the standard form submission button.
When a Submit button is clicked, the form's submit handler is executed.
$form['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Submit'),
];
You can override the submit function with the #submit property. Form validation will still be triggered. Notice the difference syntax, depending on if your code is in a module or class file.
$form['submit'] = array(
'#type' => 'submit',
'#value' => $this
->t('Submit'),
// Use in form_alter
'#submit' => ['my_submit_function'],
// Use within form class
'#submit' => [[$this, 'mySubmitFunction']]
);
You can see how this submit handler is called in FormBuilder::doBuildForm().
You can see how the form determines which button triggered submission in FormBuilder::handleInputElement().
The Submit element extends Button, so it will inherit all of it's properties.
class Submit extends Button {
public function getInfo() {
return [
'#executes_submit_callback' => TRUE,
] + parent::getInfo();
}
}
Actually, all the class does is set #executes_submit_callback = TRUE. As the name implies, this causes the button to trigger a form submit. Without this, a button will still be validated and rebuilt, allowing a form to process user input and reload, IE for multi step forms or adding an item to a multi value field.
Validation can be skipped for a button by setting the #limit_validation_errors property.
#button_type sets a class as button-BUTTON_TYPE. See Button::preRenderButton(). Many themes have support for 'primary', and 'danger'.
Here's what the node form submit buttons look in Seven - 'this is primary', no button_type, and 'danger':
These are added to the form in EntityForm::actionsElement() and NodeForm::actions().