0

I am try to display an success message after submitting my form and redirect to next page. The code I am using is the following.

public function submitForm(array &$form, FormStateInterface $form_state) {
  drupal_set_message(t('Form Submitted Successfully'), 'status', TRUE);
}

It doesn't work for me.

Is there any alternate way to do it? What code should I use to display a success message?

  • Can you show more code? Did you add the message properly in your submit handler? – Fons Vandamme Mar 1 '17 at 5:30
  • yes 'public function submitForm(array &$form, FormStateInterface $form_state) { drupal_set_message(t('Form Submitted Successfully'), 'status', TRUE);' – Karthiga Mar 1 '17 at 5:44
  • 1
    flushed the cache? – No Sssweat Mar 1 '17 at 6:11
  • Are you sure that the function is called? – Eyal Mar 1 '17 at 8:07
  • yes sure I called that method – Karthiga Mar 1 '17 at 8:38
0

The above code should work.Make sure your form is loading. Clear the cache. Steps given in below link I feel useful.just cross check the steps you followed with this link.Hope it is helpful. http://valuebound.com/resources/blog/step-by-step-method-to-create-a-custom-form-in-drupal-8

0

i think you need to clear your cache. the same problem occurred with me once...

  • Yeah I clearr the cache its not working – Karthiga Mar 1 '17 at 6:33
  • use dsm(t('Form Submitted Successfully'), 'status', TRUE); But that will only work if you have devel module installed. Let me know it worked or not. – Anirban Neogi Mar 1 '17 at 6:36
  • i have devel module but its not working – Karthiga Mar 1 '17 at 6:41
  • once clean urls also...and close your xampp and restart again.... Can u share the the screenshot??.. Like which type of form are you using Flexiform, Entityform or Webform??? if problem persists... – Anirban Neogi Mar 1 '17 at 6:47
  • drupal web forms – Karthiga Mar 1 '17 at 6:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.