0

I would like to changing a title of a button in a form, and I would like to have a tool for debug, like devel or another, so I can see in real time, after a page is loaded, what is the structure in forms, subcomponents, name of every field.

So I know how could add a line to the code in my custom module to change the title of a form button.

How would you do it? Steps, method, tools, please share.

Note: These are my first steps in programming modules, changing simple things for now.

Thanks for your suggestions!

1 Answer 1

1

Debugging in Drupal can be a bit frustrating when you first start out but you'll get the hang of it quickly :)

Debug is a really convenient Drupal function to output your form array (or any array/object) from any custom module/template.

In the case of your form, you can invoke hook_form_alter in you custom module to call the debug of your form. (You can find the form ID by looking at the page code and replacing the - with _. For example "user-login-form" would be "user_login_form" here)

 function YOUR_MODULE_NAME_form_alter(&$form, $form_state, $form_id) {
   if($form_id == 'your_form_id') {
     debug($form,'form',TRUE);   
   }
 }

Then (after clearing caches) once you visit the page with the form, Drupal will output the $form array as an entry in your watchdog log (admin/reports/dblog).

4
  • Hi @longboardnode!. Thank you for your help. In my particular issue, my button is displayed by vbo views module. And I want to create a custom module to change the title of the button. I need a tool or method to know the name of the form and the name of the submit button to change the title.
    – bunset
    Apr 28, 2016 at 13:22
  • 1
    That's what form_alter does, regardless of which module created the form. You can find the button's ID in your browser's source code as well (for the Search magnifying glass button on Drupal.org home page, it's "edit-submit" for example) In the hook_form_alter page I linked to above there is lots of information and examples. In your case, you can use the function sample in my answer and replace the debug line with something like: $form['edit_submit']['value']='NewTitle'; Apr 28, 2016 at 14:59
  • thanks @longboardnode! very instructive. I would like too, install a debug environment on my localhost to inspect the values of variables while loads the page in realtime. Can you give me any suggestion about this?
    – bunset
    Apr 28, 2016 at 18:03
  • 1
    sure thing @bunset you can output the debug function more info here anywhere to inspect the variable of your choice. So if you want to inspect the node object of a specific content type, add debug($node,'Node',TRUE); at the top of that content-type's template. Or you can just add that to your main template with an if ($node) { debug($node,'Node',TRUE); } Hope that helps. Apr 28, 2016 at 19:01

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.