2012-05-29 3 views
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 я я удалить эту функцию все, кажется, работает. Может ли кто-нибудь помочь мне в этом вопросе?Ajax не работает в пользовательской темы в Друпал 7.x

ответ

0

Решите его. Я мой template_preprocess_contact_theme_form Я удаляю form_build_id, form_id, который является неправильным, а не скрывает, и я удалял значения.

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); 
+0

Решите его. Я мой template_preprocess_contact_theme_form Я удаляю form_build_id, form_id, который является неправильным, а не скрывает, и я удалял значения. – goblin2986