1

In my form validation and submit functions, kpr() is not being called. Is there a better way to check that I'm in those functions? If kpr() isn't ideal to output my $form_state array, then what is ideal?

4

Everything that is output with drupal_set_message() (the function that kpr() uses to output the message) could not be visible from the browser if code redirects the user to another page after drupal_set_message() is called and before the page is rendered. After a form is submitted, the users are redirected to a page whose URL is set in $form_state['redirect'] or $_GET['destination']; the latter takes the precedence over the former.
To avoid the users are redirected after the form is submitted, you can:

  • Set $form_state['rebuild'] to TRUE
  • Set $form_state['redirect'] to FALSE

Setting $form_state['no_redirect'] to TRUE would have the same effect, but form builder functions, form validation handlers, and form submission handlers should never set $form_state['no_redirect'].

A preferred method would be calling watchdog(). If you have the Database Logging module enable, then the message output from the module will be visible in admin/reports/dblog.

For debugging messages, you can call watchdog() passing WATCHDOG_DEBUG as value for the $severity parameter.

References

  • I set form_state['rebuild'] = TRUE, and I was able to get kpr() output. – vintorg Aug 13 '13 at 19:07
  • I expanded the answer to show other ways to avoid users are redirected after form submission. – kiamlaluno Aug 13 '13 at 19:59

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.