8

I want to use the dsm() function of the Devel module to print the $form array of a form, where the form_id is search_theme_form. How to do that?

3 Answers 3

12

Start a custom module, insert this code:

/**
* Implements hook_form_alter().
*/
function foo_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'search_theme_form') {
    dpm($form);
  }
}

Also, you might want to use dpm() over dsm() since the latter is a legacy function.

2
  • 1
    @sokratis you can also download my simple module for forms developping - it adds the dpm($form_state) even after submitting
    – mojzis
    Commented Oct 12, 2012 at 18:04
  • is this still accurate?
    – Jeff
    Commented Jan 28, 2014 at 15:54
3
function THEME_form_search_theme_form_alter (&$form, &$form_state){

krumo ($form); // you can use DSM as well here

}

Replace THEME with your theme name and put that in your template.php, if you want to do that from a module then replace THEME by your module name and put that funciton in your .module file

2

Use drupal_retrieve_form to get the structured form array:

$form_state = array();
dsm(drupal_retrieve_form('search_theme_form', &$form_state));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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