Drupal 모듈을 만드는 데 문제가 있습니다. 데이터베이스에 추가하기위한 양식을 만들었지 만 여기에 일부 레코드를 편집하기 위해 양식을 만드는 데 아무런 운이 필요하지 않습니다. 내 문제입니다. 문제는 데이터베이스에서 폼로드로 값을로드하고 변경 한 다음 새 값을 제출하기 전에 제출 단추 폼 새로 고침을 클릭하는 경우입니다. 따라서 그것은 데이터베이스와 동일한 것으로 업데이트됩니다. 여기에 제출 형태 코드drupal 모듈에서 양식을 편집 하시겠습니까?
function edit_form($form, &$form_state) {
$query = db_select('activity', 'f')
->fields('f')
->condition('IDA', $_GET['edit']);
$thefile = $query->execute();
$title = "";
$desc = "";
$file = "";
$privacy = "";
while($record = $thefile->fetchAssoc())
{
$title = $record['title'];
$desc = $record['description'];ick submit button form refresh before it submit new values. So it updates into database same thing as it was. Here is a good :
function edit_form($form, &$form_state) {
$query = db_select('activity', 'f') ->fields('f') ->co
$file = $record['trainingresource'];
$privacy = $record['privacy'];
}
$form['activity'] = array(
'#type' => 'fieldset',
'#title' => t('Create a new activity'),
'#tree' => TRUE,
);
$form['activity']['title'] = array(
'#type' => 'textfield',
'#title' => t('Title'),
'#description' => t('Please enter the title here.'),
'#value' => t($title),
);
$form['activity']['description'] = array(
'#type' => 'textarea',
'#title' => t('Enter Description'),
'#value' => t($desc),
'#description' => t('Please put description here.'),
);
/* $form['activity']['date'] = array(
'#type' => 'date',
'#title' => t('Enter activity date'),
'#description' => t('Please put activity date in here.'),
); */
$form['activity']['file'] = array(
'#type' => 'file',
'#title' => t('Submit activity file'),
'#value' => t($file),
'#description' => t('Please files in here.'),
);
$form['activity']['security'] = array(
'#type' => 'radios',
'#title' => t('Privacy'),
'#value' => t($privacy),
'#options' => array('True'=>t('True'),'False'=>t('False')),
);
// Description
$form['hidden'] = array('#type' => 'value', '#value' => 'is_it_here');
$form['submit'] = array('#type' => 'submit', '#value' => t('Save'));
return $form;
}
: 그리고 누군가가 같은 문제가 있거나이 문제를 해결하는 방법을 알고 있다면
function edit_form_submit($form, $form_state) {
$idt = $_GET['edit'];
$title = trim($form_state['values']['activity']['title']);
$desc = trim($form_state['values']['activity']['description']);
//$date = trim($form_state['values']['activity']['date']['year']."-".$form_state['values']['activity']['date']['month']."-".$form_state['values']['activity']['date']['day']);
$file = "file";
$privacy = trim($form_state['values']['activity']['security']['#value']);
$nid = db_update('activity') // Table name no longer needs {}
->fields(array(
'title' => $title,
'description' => $desc,
//'date' => $date,
'trainingresource' => $file,
'privacy' => $privacy,
))
->condition('IDA', $idt,'=')
->execute();
drupal_set_message($idt);
drupal_set_message("Added into database");
drupal_goto('activity', array('query'=>array(
'activ'=>$_GET['activ'],
)));
}
이, 저를 도와주세요 여기에 코드입니다. 사전에
감사합니다.
코드를 편집하고 여분의 부분을 제거 할 수 있습니까? D34dman이 지적했듯이이 코드는 동일한 함수를 두 번 정의합니다. – kiamlaluno