Ajax替换方法没有工作错误

时间:2014-02-10 14:18:10

标签: ajax callback

Ajax替换方法在这些代码中不起作用。但是append方法正在工作。

<?php    
$currentDate = date("Y-m-d");
$currentTime = date("Y-m-d");
global $user;

 function form_test_permission()
 {
 return array(
      'submit_form_test' =>array(
      'title' =>t('Submit_form_test'),
      'description' => t('Submit the form_test form'),
),
);
}


  function form_test_menu() {
    $items = array();
    $items['production'] = array(
        'title' =>'Production',
        'type' => MENU_NORMAL_ITEM,
        'access arguments' => array('submit_form_test'),
        'page callback' => 'drupal_get_form',
        'page arguments' => array('form_test_form'),

    );

  return $items;
}

function form_test_form($form,&$form_state) {
  $form['production'] = array(
    '#title' => t('production'),
    '#type' => 'hidden',
    '#value'=> '1',
    );
    $form['production1'] = array(
    '#title' => t('production1'),
    '#type' => 'hidden',

    );

    $form['production_date'] = array(
    '#title' => t('production_date'),
    '#type' => 'hidden',
     '#value' => date('Y-m-d'),
    );
    $form['production_time'] = array(
    '#title' => t('production_time'),
    '#type' => 'hidden',
     '#value' => date('H:i:s'),
    );
    $form['production23'] = array(
    '#title' => t('production23'),
    '#type' => 'hidden',
    '#value'=> '1',
    );


   $form['button2'] = array(
    '#value' => 'UNDO',
    '#type' => 'submit',
    '#prefix' => '<div  class="test">',
    '#suffix' => '</div>',
    '#submit' => array('form_test_form_button2'),


    );

  $form['button1'] = array(
    '#value' => '  ADD  ',
    '#type' => 'submit',
    '#prefix' => '<div  class="test1">',
    '#suffix' => '</div>',
    '#submit' => array('form_test_form_button1'),
    '#ajax' => array(
      'callback' => 'ajax_example_submit_driven_callback',
        'method' => 'replace',    
        'effect' => 'fade',
        'event' =>'click',
        'wrapper' => 'countvalue',


    ),

    );

    $form['start_counter'] = array(

    '#type' => 'select',
    '#options' => array (
        'Start' => 'Start',
      '2501 ' => '2501 ',
      '302 ' => '302 ',
      '1107 ' => '1107', 
      '1104' => '1104',
      '0106' => '0106',
      '0305' => '0305',
      '0103' => '0103',
    ),
    '#prefix' => ' <div class="box chart gradient" style="width:30%;float:left;margin-top: -186px;">

                            <div class="title">

                                <h4>

                                    <span style="text-align:center;">Downtime</span>
                                </h4>

                            </div>
                            <div class="content" style="padding-bottom:0;">
                              <p class="dowtime-show" id="counter"></p>',

   );
   $form['start_counter1'] = array(

    '#type' => 'textfield',


   );
    $form['stop_counter'] = array(

    '#type' => 'select',
    '#options' => array (
    'Stop'=>'Stop',
      'Mechanical' => 'Mechanical',
      'Electrical' => 'Electrical',
      'Programming' => 'Programming', 
      'Setup' => 'Setup',
      'PlannedMaintenance' => 'PlannedMaintenance'
    ),
 '#suffix' => '</div> </div>',

   );
   $form['counter'] = array(

    '#type' => 'textfield',

    );

       $form['button3'] = array(
    '#value' => 'submit',
    '#type' => 'submit',
    '#submit' => array('form_test_form_button3'),


    );
  return $form;
}

function ajax_example_submit_driven_callback($form,$form_state){


 $result = db_query("SELECT * FROM  form_test WHERE production_date='2014-02-10' and production_time between '01:00:00' and '02:00:00'");
    $prod_1= $result->rowcount();
    $form['#tree'] = TRUE;
     $form_state['rebuild'] = TRUE;
    return 'count value is:'.$prod_1.'';

}   



function form_test_form_button1($form,&$form_state){

    $ft_id = db_insert('form_test')
    ->fields(array(
    'production' => $form_state['values']['production'],
    'production_date' => $form_state['values']['production_date'],
    'production_time' => $form_state['values']['production_time'],
    'production1' => $form_state['values']['production1'],

    ))
    ->execute();
     $form_state['rebuild'] = true;

    }

function form_test_form_button2($form,&$form_state){

    $ft_id = db_insert('form_test1')
    ->fields(array(
    'production23' => $form_state['values']['production23'],
    'production_date' => $form_state['values']['production_date'],
    'production_time' => $form_state['values']['production_time'],
    ))
    ->execute();
    }

function form_test_form_button3($form,&$form_state){

    $ft_id = db_insert('downtime1')
    ->fields(array(
    'start_counter1' => $form_state['values']['start_counter1'],
    'stop_counter' => $form_state['values']['stop_counter'],
    'counter' => $form_state['values']['counter'],
    'production_date' => $form_state['values']['production_date'],
    'production_time' => $form_state['values']['production_time'],
    ))
    ->execute();
    }

我花了很多时间才得到结果,却无法得到它。任何人都知道如何解决这些错误。主要问题是它在使用替换方法时不会改变值。

0 个答案:

没有答案