2014-10-07 3 views
1

에서 여러 항목을 삭제하기 전에 내가 단일 항목을 삭제하기 전에 확인을 요청하며 다음과 같이 잘 작동 :요청 확인 드루팔

function tema_delete_confirm ($form, &$form_state, $tema) { 
    $form['id'] = array('#type' => 'value', '#value' => $tema); 

    return confirm_form ($form, 
     'Are you sure you want to delete (tema: '.$tema.')?', 
     'admin/temas', 
     'This action cannot be undone.', 
     'Delete', 
     'Cancel' 
    ); 
} 

/** 
* Executes "tema" deletion. 
* 
* @see tema_delete_confirm() 
*/ 
function tema_delete_confirm_submit ($form, &$form_state) { 
    if ($form_state['values']['confirm']) { 
     $id = $form_state['values']['id']; 
     tema_delete($id); 
     drupal_set_message('Tema: '.$id.' has been deleted.'); 
    } 
} 

것은이 checkox로 표시된 항목을 삭제하려면 여러입니다, 확인 페이지 메시지가 표시되지 않습니다, 제출 중 후 내가 확인 "페이지"내가 잘못

/** 
* Multiple "temas" deletion confirmation form for temas_admin_content(). 
*/ 
function temas_multiple_delete_confirm ($form, &$form_state, $temas) { 
    $form['temas'] = array('#prefix' => '<ul>', '#suffix' => '</ul>', '#tree' => TRUE); 

    // array_filter returns only elements with TRUE values 
    foreach ($temas as $id => $value) { 
     $title = db_query('SELECT nombre FROM {sescam_tema} WHERE id = :id', array(':id' => $id))->fetchField(); 
     $form['temas'][$id] = array(
      '#type' => 'hidden', 
      '#value' => $id, 
      '#prefix' => '<li>', 
      '#suffix' => check_plain($title) . "</li>\n", 
     ); 
    } 

    $form['#submit'][] = 'temas_multiple_delete_confirm_submit'; 

    $confirm_question = format_plural(count($temas), 
      'Are you sure you want to delete this item?', 
      'Are you sure you want to delete these items?'); 

    return confirm_form($form, 
     $confirm_question, 
     'admin/temas', 
     'This action cannot be undone.', 
     'Delete', 
     'Cancel'); 
} 

/** 
* Form submission handler for temas_multiple_delete_confirm(). 
*/ 
function temas_multiple_delete_confirm_submit ($form, &$form_state) { 
    die('hola'); 
    if ($form_state['values']['confirm']) { 
     temas_delete_multiple(array_keys($form_state['input']['temas'])); 
     $count = count($form_state['input']['temas']); 
     drupal_set_message(format_plural($count, 'Eliminado 1 tema.', 'Eliminados @count temas.')); 
    } 
    $form_state['redirect'] = 'admin/temas'; 
} 

어떤 생각을하고있는 중이없이 hello 로그를 얻을?

답변

-1

양식을 제출할 때 서버에서 일부 ID를 유지하려고 시도하는 것처럼 보입니다 ... Drupal은 실제로 value 요소 유형을 사용하여 렌더링하지 않고도이 값을 저장할 수 있습니다. 그들 고객 측; 그것을 사용하는 것이 더 합리적 일 것입니다.

귀하의 코드는 몇 가지 사소한 조정을 너무 성능과 가독성을 위해 개선 할 수

:

function temas_multiple_delete_confirm ($form, &$form_state, $temas) { 
    $form['temas'] = array('#prefix' => '<ul>', '#suffix' => '</ul>', '#tree' => TRUE); 

    $args = array(':ids' => $temas); 
    $data = db_query('SELECT DISTINCT nombre FROM {sescam_tema} WHERE id IN (:ids)', $args)->fetchCol(); 

    $form['temas'] = array(
    '#type' => 'value', 
    '#value' => $data, 
); 

    $form['#submit'][] = 'temas_multiple_delete_confirm_submit'; 

    $confirm_question = format_plural(count($temas), 
     'Are you sure you want to delete this item?', 
     'Are you sure you want to delete these items?'); 

    return confirm_form($form, 
    $confirm_question, 
    'admin/temas', 
    'This action cannot be undone.', 
    'Delete', 
    'Cancel'); 
} 

그리고 당신의 제출 기능 :

function temas_multiple_delete_confirm_submit ($form, &$form_state) { 
    $temas = $form_state['values']['temas']; 
    temas_delete_multiple($temas); 
    $count = count($temas); 
    drupal_set_message(format_plural($count, 'Eliminado 1 tema.', 'Eliminados @count temas.')); 

    $form_state['redirect'] = 'admin/temas'; 
}