How do I render form fields in my custom.tpl.php template?

Here’s my dilemma, I built a custom form-based module that allows a user to vote on a future conference location but I’m having a issue printing or rendering my form fields to have them display in my custom block template.

eventvoting.module

<?php /**  * @file  * Title        : Drupal 7 Event Voting form in a block pattern with template file  * Author       : Kenyon M. Johnston  *  * Web application form that allows site visitors to vote on what city they  * would like to see host their favorite event next year.   */    /**  * Implmentation of hook_permission()  */ function eventvoting_permission(){   return array (     'Administer event voting form' => array(       'title' => t('Administer event voting form'),       'description' => t('Allows users to implement custom css class for the Event Voting Form module'),     )   ); }   /**  * Implements hook_block_info().  */ function eventvoting_block_info() {   $block['eventvoting_block'] = array(     'info' => t('Event Voting Form Block'),     'cache' => DRUPAL_CACHE_PER_ROLE,   );     return $block; }  /**  * Implementation of hook_block_view()  */ function eventvoting_block_view($delta = '') {   $block = array();    switch ($delta) {     case 'eventvoting':       $block['subject'] = t('');       $block['content'] = array(         '#theme' => 'eventvoting',         '#vote_event_name' => variable_get('event_name'),         '#vote_city' => variable_get('city'),         '#vote_name' => variable_get('name'),         '#vote_email' => variable_get('email'),         '#vote_submit' => variable_get('submit'),       );     break;   }   return $block; }  /*  * Implements hook_theme  */ function eventvoting_theme(){   return array (     'eventvoting' => array (       'arguments' => array(         'vote_event_name' => NULL,         'vote_city' => NULL,         'vote_name' => NULL,         'vote_email' => NULL,         'vote_submit' => NULL,       ),       // Use a template file called eventtheme.tpl.php       'template' => 'theme/eventtheme',     ),   ); }  /**  * Implements hook_menu(). */ function eventvoting_menu() {   $items['event-voting-form'] = array(     'title' => 'Event Voting Form',     'page callback' => 'drupal_get_form',     'page arguments' => array('eventvoting_form'),     // Use the default/standard site configuration permission.     'access arguments' => array('administer site configuration'),     'type' => MENU_NORMAL_ITEM,   );   return $items;     }   /**  * Creates/returns a form to configure the block's variables.  *  * @param array $form  * @param array $form_state  * @return array  */ function eventvoting_form($form, &$form_state) {    $form['event_name'] = array(         '#title' => t('Select an event:'),         '#type' => 'textfield',         '#default_value' => variable_get('event_name'),         '#required' => TRUE,         '#weight' => 0,     );      $form['city'] = array(         '#title' => t('Vote for a city:'),         '#type' => 'textfield',         '#default_value' => variable_get('city'),         '#required' => TRUE,         '#weight' => 0,     );      $form['name'] = array(         '#title' => t('Your name:'),         '#type' => 'textfield',         '#default_value' => variable_get('name'),         '#required' => TRUE,         '#weight' => 0,     );      $form['email'] = array(         '#title' => t('Your email:'),         '#type' => 'textfield',         '#default_value' => variable_get('email'),         '#required' => TRUE,         '#weight' => 0,     );      $form['save'] = array(         '#type' => 'submit',         '#value' => t('Vote'),       );      return $form; }  **<h2><strong>eventheme.tpl.php (inside the "theme" directory)</strong></h2>**  <?php  /*  * File         : eventtheme.tpl.php  * Title        : Drupal 7 Event Voting Location form in a block pattern with template file  * Author       : Kenyon M. Johnston  *  */  ?>  <div class="event-voting-form">     <form>           <h2>Vote for Next Year's Event</h2>          <div id="vote_event_name">             <?php print $vote_event_name; ?>         </div>          <div id="data-fieldset">             <div id="vote_city">                 <?php print $vote_city ?>             </div>             <div id="vote_name">                 <?php print $name ?>             </div>             <div id="vote_email">                 <?php print $email ?>             </div>             <div id="vote_submit">                 <?php print $submit ?>             </div>         </div>      <?php print drupal_render_children($form); ?>     </form> </div> 

My goal is to render my fields of choice. The theme renders in the block but not the fields,

This has been racking my brain for a few hours now, any help and assistance would be GREATLY appreciated.

Sponsored by SupremePR
This article was republished from its original source.
Call Us: 1(800)730-2416

Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.

FREE Drupal SEO Audit

Test your site below to see which issues need to be fixed. We will fix them and optimize your Drupal site 100% for Google and Bing. (Allow 30-60 seconds to gather data.)

Powered by

How do I render form fields in my custom.tpl.php template?

On-Site Drupal SEO Master Setup

We make sure your site is 100% optimized (and stays that way) for the best SEO results.

With Pixeldust On-site (or On-page) SEO we make changes to your site’s structure and performance to make it easier for search engines to see and understand your site’s content. Search engines use algorithms to rank sites by degrees of relevance. Our on-site optimization ensures your site is configured to provide information in a way that meets Google and Bing standards for optimal indexing.

This service includes:

  • Pathauto install and configuration for SEO-friendly URLs.
  • Meta Tags install and configuration with dynamic tokens for meta titles and descriptions for all content types.
  • Install and fix all issues on the SEO checklist module.
  • Install and configure XML sitemap module and submit sitemaps.
  • Install and configure Google Analytics Module.
  • Install and configure Yoast.
  • Install and configure the Advanced Aggregation module to improve performance by minifying and merging CSS and JS.
  • Install and configure Schema.org Metatag.
  • Configure robots.txt.
  • Google Search Console setup snd configuration.
  • Find & Fix H1 tags.
  • Find and fix duplicate/missing meta descriptions.
  • Find and fix duplicate title tags.
  • Improve title, meta tags, and site descriptions.
  • Optimize images for better search engine optimization. Automate where possible.
  • Find and fix the missing alt and title tag for all images. Automate where possible.
  • The project takes 1 week to complete.