0
<?php
/** hook_menu **/
function example_contact_form_menu() {
    return array(
    'contact_form_test' => array(
      'page callback' => 'contact_form_test',
      'page arguments' => array(),
      'access arguments' => TRUE,
      'type' => MENU_CALLBACK,
    ),
    'contact_form_test_1' => array(
      'page callback' => 'drupal_get_form',
      'page arguments' => examplexample_contact_form_form'),
      'access arguments' => TRUE,
      'type' => MENU_CALLBACK,
    )
    );
}
function contact_form_test()
{
    drupal_add_css(drupal_get_path('module', 'example_contact_form') . '/example_contact_form.css');
    dpm(drupal_get_form('example_contact_form_form'));
    return render(drupal_get_form('example_contact_form_form'));
}
/**
 * Implementation of hook_form().
 */
function example_contact_form_form($form, &$form_state){
    $form=drupal_build_form('example_form_form',$form_state);
    $form['first_name']['#size']=25;
    $form['last_name']['#size']=25;
    unset($form['submit_form']);
     //adding new fields
     $form['box'] = array(
    '#type' => 'markup',
    '#prefix' => '<div id="box">',
    '#suffix' => '</div>',
    '#markup' => '<h1>Initial markup for box</h1>',
  );
      $form['comment'] = array(
    '#title'=> t('Comments'),
    '#type' => 'textarea',
     '#value'=>'Type Here',
    '#description' => t(''),
    '#default_value' => '',
    '#attributes'=>array(
             'onfocus'=> "if(this.value=='Type Here')this.value='';"
            )
    );
    $form['questions'] = array(
    '#type' => 'select', 
    '#title' => t('Whats in your mind'), 
    '#default_value' => array(), 
    '#options' => array(
      'What\'s in your mind' => 'What\'s in your mind', 
      'Question 1' => 'Question 1', 
    ), 
  );
     $form['sub_form'] = array(
    '#type' => 'button',
    '#ajax' => array(
      'callback' => 'example_contact_form_js',
      'wrapper' => 'box',
      'name' => 'submit1',
    ),
    '#value' => t('Submit'),
  );
     unset($form['#theme']);
     $form['#theme'] = array('example_form_form', 'contact_theme_form');
     $form['#validate'] = array('example_contact_form_form_validate');
     $form['#submit'] = array('example_contact_form_form_submit');
     return $form;
}

function example_contact_form_form_validate($form, &$form_state){
    dpm($form_state,t('Form State Validate'));
}


function example_contact_form_js($form, &$form_state){
      $element = $form['box'];
      $element['#markup'] = "Clicked submit ({$form_state['values']['op']}): " . date('c');
      return $element;
}
function advanced_form_callback($form, &$form_state) {
  $city_name = form_result_helper($form_state);
  $element = $form['status'];
  $element['#markup'] = t('You submitted @city', array('@city' => $city_name));
  print 'BHASKAR';
}

function example_contact_form_form_submit($form, &$form_state){
    dpm($form_state,t('Form State Submit'));
}

// Menu callback
function example_contact_form_theme(){
    return array
    (
        'contact_theme_form' => array
        (
                'render element' => 'form',
                'template' => 'contact-signup',
                'path' => drupal_get_path('module', 'example_contact_form').'/templates',
                'arguments' => array('form' => null),
        ),
    );
}

function template_preprocess_contact_theme_form(&$variables) {
  $form=$variables['form'];
  foreach (element_children($form) as $key) {
              unset($form[$key]['#title']);
              $variables[$key]=render(($form[$key]));
              unset($form[$key]);    
 }
$variables['contact']=drupal_render_children($form);
}
?>

问题是当我试图渲染 template_preprocess_contact_theme_form 中的每个元素时,我删除了这个函数,一切似乎都在工作。有人可以帮我解决这个问题吗?

4

2 回答 2

0

解决这个问题。我的 template_preprocess_contact_theme_form 我正在删除 form_build_id,form_id 这是错误的,而不是隐藏,我正在删除这些值。

于 2012-07-05T23:09:30.010 回答
0

你的<form>标签出现了吗?
在您的表单主题中,您可能必须呈现表单子项,然后使用theme_form().

$buildform = '&lt;div&gt;'.drupal_render($form['elem1']).'&lt;/div&gt;';
$buildform .= drupal_render($form['elem2']);
$buildform .= drupal_render($form['form_build_id']);
$buildform .= drupal_render($form['form_id']);
$form['element']['#children'] = $buildform;
$output = theme_form($form);
于 2012-06-18T08:18:30.423 回答