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 iiの各要素をレンダリングしようとしたときに、この関数を削除すると、すべてが機能しているように見えることです。誰かがこの問題について私を助けることができますか?

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 に答える