Created
November 13, 2017 11:57
-
-
Save Dropa/160de5154e3e3358378c9e72d080c18a to your computer and use it in GitHub Desktop.
proper way to do different submits
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Drupal\general\Form; | |
use Drupal\Core\Form\FormBase; | |
use Drupal\Core\Form\FormStateInterface; | |
/** | |
* List tests arranged in groups that can be selected and run. | |
*/ | |
class TestForm extends FormBase { | |
/** | |
* {@inheritdoc} | |
*/ | |
public function getFormId() { | |
return 'testform'; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function buildForm(array $form, FormStateInterface $form_state) { | |
$form = [ | |
'sub' => [ | |
'#type' => 'container', | |
'submit' => [ | |
'#type' => 'submit', | |
'#value' => 'Sub me too!', | |
'#name' => '2', | |
'#submit' => ['::dumptwo'], | |
'#weight' => 2, | |
'#parents' => [2], | |
], | |
], | |
'submit' => [ | |
'#type' => 'submit', | |
'#value' => 'Sub me!', | |
'#name' => '1', | |
'#submit' => ['::dumpone'], | |
'#weight' => 1, | |
'#parents' => [1], | |
], | |
]; | |
return $form; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function dumpone(array &$form, FormStateInterface $form_state) { | |
dump(1); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function dumptwo(array &$form, FormStateInterface $form_state) { | |
dump(2); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function submitForm(array &$form, FormStateInterface $form_state) { | |
// meh. | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment