2016-02-17 56 views
0

爲什麼我的表單提交時我的提交處理程序不被調用?以下函數是從頁面模板中調用的...在引導模式窗口中...因此模式會在頁面加載時加載。我有一種感覺,條件是與提交處理程序被調用相干涉,或者我沒有返回什麼東西?此代碼位於表單的模塊中。我正在使用默認的提交處理程序。Drupal表單提交處理程序不工作,但爲什麼?

function winner_modal_form_communication($node) { 

    if ($_SERVER['REQUEST_METHOD'] != 'POST') {  

我測試,看看它已經被張貼,否則兩個日期是從外地減去因爲它(在一次後負荷,然後一次)被調用兩次。如果已經發布(因爲這意味着他們填寫了獲勝表格),我會打印出確認信息。

 // WINNING DATES 

     if (!empty($node->field_win_dates{'und'}{0}{'value'})) { 

      $winDatesString = $node->field_win_dates{'und'}{0}{'value'}; 

      $winDatesArray = explode(", ", $winDatesString);       

     } 

     // TODAYS DATE 

     $todaysDatePST = date("Y-m-d H:i:s");          


     // EVENT DATES 

     $eventDateUTC = $node->field_date{'und'}{0}{'value'};      

     $eventDateObject = new DateTime($eventDateUTC, new DateTimeZone('UTC'));  

     $eventDateObject->setTimezone(new DateTimeZone('America/Los_Angeles'));  

     $eventDatePST = $eventDateObject->format('Y-m-d H:i:s');      

我只是設置了一些變量...然後一些條件。

 // EXPIRED EVENT 

     if ($todaysDatePST > $eventDatePST) { 

      print "Sorry, this event has expired.<br /><button type='button' class='btn btn-default' data-dismiss='modal'>Continue</button>"; 

     } 

     // WINNER 

     else if (($todaysDatePST > $winDatesArray[0]) && (!empty($winDatesString))) { 


      print "You've just won<br />TWO FREE TICKETS<br />to see " . $node->title . "!"; 


      $form = drupal_get_form('winner_modal_form'); 


      print drupal_render($form); 


      unset($winDatesArray[0]);              


      $newWinningDatesString = implode(", ",$winDatesArray);       


      $node->field_win_dates{'und'}{0}{'value'} = $newWinningDatesString;    


      node_save($node); 


     } 


     // NO WINNER 

     else { 

      print "You didn't win tickets to " . $node->title. ", but you can still learn more by pressing the continue button."; 

      print "<br /><button type='button' class='btn btn-default' data-dismiss='modal'>Continue</button>"; 


     } 


    } 


    // WINNER CONFIRMATION 

    else { 


     print "Thank you! This is the confirmation modal window. That's right, you were the winner!<br /><button type='button' class='btn btn-default' data-dismiss='modal'>Continue</button>"; 


    } 


} 

如果我刪除上述條件提交處理程序的作品。

function winner_modal_form_submit($form, &$form_state) { 

    dpm("It worked!"); 

} 

我在做什麼錯?任何洞察力將不勝感激(我是編程新手)。

回答

0

嘗試使用方括號而不是大括號。例如:$ node-> field_win_dates ['und'] [0] ['value']。

+0

好吧,它更具可讀性,但那不是。 – know1

0

在Drupal中,做爲 Drupal asks

如果您需要從表單獲取數據,只需使用* _validate和* _submit函數。

無需處理$ _SERVER ['REQUEST_METHOD']。

相關問題