Im trying to alter the module "zendek_forms"

It states: There are four fields in the form (name, e-mail, subject, and description), but more fields can be added in hook_form_alter and the submit handler will recognize fields prefixed with "zendesk_" and pack them in the API call to Zendesk.

I am absolutely clueless on how to do this, even where to begin. Any help would be greatly appreciated.

1 Answer 1


hook_form_alter is a drupal API function. You can google "hook_form_alter" and the 1st result will be the API documentation for this function; it includes examples.

Using this "hook" function you can inject, or otherwise change, any form in your drupal website. A "form" is an HTML construct that can send data to a webserver via either POST or GET.

So, you can create a custom drupal Module (which consist of in this case an .info file and a .module file). In your module you can create a function that implements "hook_form_alter" and adds in the zendesk field.

A simple simple example of this would be:

# in the below examples lets assume you have named your module folder as "zext" (kinda short for zendesk extensions .... i dunno :P

# in zext.info
name = Custom Zendesk Form Extensions
descrption = We want to add custom fields to the zendesk form.
package = Other
core = 7.x

# in zext.module

 * Implements hook_form_alter().
 * Alter the zendesk form and add a custom color text field.
function zext_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'zendesk_form') {
    $form['zendesk_favorite_color'] = array(
      '#type' => 'textfield',
      '#title' => t('Favorite Color'),
      '#description' => t('Please tell us what your favorite color is!'),
      '#weight' => 99,

# that is all the code that would be in the 2 files.

With the above 2 small pieces of code we have modified the default zendesk_form (I assume its $form_id is zendesk_form ... it may be different examine the module's code to see how it IDs the forms ...) and added 1 single new custom field to allow the visitor to submit their favorite color. Drupal doesn't store these values anywhere -- they are just passed onto Zendesk upon form submission; You simply need to create the folder + 2 files and install the module in the drupal administration. Your module folder should be called zext.

There is alot of documentation online for creating modules, and using hook_form_alter. Look on drupal.org and Google.

Happy Coding!

  • This is a great start, I have a couple questions though. I created the module and info files. Uploaded to server. I activated the module. Now, Im unclear where Im supposed to see these new custom fields? Should they appear in the form? Commented Mar 11, 2014 at 1:26
  • Should I be editing the original ZD module or is this all done strictly in the new module? Commented Mar 11, 2014 at 1:32
  • Also, how would I make a field 'hidden'? I feel like Im pretty close to making this work. For a real world example of the custom fields I want to add, they would be "Product (23407353)" and "Channel (23659573)". Parenthesis are custom ids. If I were to add those to the abiove code, what would it look like? I appreciate your feedback! Commented Mar 11, 2014 at 1:35
  • my directions were clear, please read carefully. The code above is in a new custom module. With the proper $form_id it should appear in the form your alter function is targeting. Use the Form API to add whatever types of fields you want api.drupal.org/api/drupal/… alternatively see the Examples module for code samples and usage: drupal.org/project/examples
    – tenken
    Commented Mar 11, 2014 at 19:32

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.