Created
September 17, 2018 11:52
-
-
Save henideepak/c038b08fc8ad4d77ff1493fedfb1862f to your computer and use it in GitHub Desktop.
Drupal 8 form submit show "Success! Dialogbox".
This file contains 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
use Drupal\Core\Form\FormStateInterface; | |
use Drupal\Core\Ajax\AjaxResponse; | |
use Drupal\Core\Ajax\OpenModalDialogCommand; | |
use Drupal\Core\Ajax\CloseModalDialogCommand; | |
use Drupal\Core\Ajex\RedirectCommand; | |
use Drupal\Core\Ajex\HtmlCommand; | |
use Drupal\Core\Url; | |
use Drupal\Core\Ajex\ReplaceCommand; | |
function modual_form_example_form_alter( array &$form, FormStateInterface $form_state, $form_id ) { | |
if ($form_id == 'user_register_form' ) { | |
$form['actions']['submit']['#ajax'] = ['callback' => '_submit_message']; | |
$form['#attached']['library'][] = 'core/drupal.dialog.ajax'; | |
$form['#attached']['library'][] = 'core/jquery.form'; | |
return $form; | |
} | |
} | |
function _submit_message(array $form, FormStateInterface $form_state) { | |
$response = new AjaxResponse(); | |
// If there are any form errors, re-display the form. | |
if ($form_state->hasAnyErrors()) { | |
$response->addCommand(new ReplaceCommand('#user_register_form', $form)); | |
} | |
else { | |
$response->addCommand(new OpenModalDialogCommand("Success!", 'The modal form has been submitted.', ['width' => 800])); | |
} | |
return $response; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment