I would like to like to be able to print out what has been submitted in my form in the submission form. How can I achieve this?

  • Is this a form created yourself, or do you want to hook into a form defined in another module? Is this for debugging purposes, or do you actually want the site to show this data to the end user? – marcvangend Jul 3 '14 at 10:18
  • a form that I created for debugging process – colinam1992 Jul 3 '14 at 10:28

You can display the submitted values in your hook_form_submit() and set it like this (example):

function form_example_tutorial_7_submit($form, &$form_state) {
  drupal_set_message(t('The form has been submitted. name="@first @last", year of birth=@year_of_birth', array(
   '@first' => $form_state['values']['first'],
   '@last' => $form_state['values']['last'],
   '@year_of_birth' => $form_state['values']['year_of_birth'],
  • You can also use dpm function from devel module. It prints using Krumo all kind of variables, complex arrays included. So you can just dpm the $form_state in the submit handler as Djouuuuh suggests. – sanzante Jul 3 '14 at 10:26
  • OKaaayyy! I didn't know it was for debugging process. Of course use dpm with Devel module in the hook I suggested you. It's way easier. – Djouuuuh Jul 3 '14 at 11:58
  • I really recommend spending some time setting up XDebug and using that. Here are some links. If you use a good IDE, like PHPStorm, you get great integration with XDebug and no need to mess up your code with debugging statements. :) code.tutsplus.com/tutorials/… xdebug.org/docs/install youtube.com/watch?v=LUTolQw8K9A – Ollie Jul 8 '14 at 9:43

Its better to install devel module and use the dpm function.

function MYMODULE_FORMID_submit($form, &$form_state) {

Instead of printing stuff in the page output, I would recommend to use an IDE such as PhpStorm, Eclipse or Netbeans. Combined with Xdebug, you can set a breakpoint in the form submit function and inspect all variables available at that point. You'll find the submitted values in $form_State['values'].


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.