0
이름, 성 및 생년월일의 세 필드가 있습니다. 코드에서 제출 버튼을 누르면 데이터베이스에 쉽게 삽입되므로 편집 버튼을 클릭 할 때이 필드를 업데이트하고 싶습니다. 누구든지이 업데이트를 코딩하여 데이터베이스에 삽입 된 데이터를 넣거나 게시 코드를 작성하도록 도와주십시오.drupal7에서 사용자 정의 양식을 사용하여 필드를 업데이트하는 방법
<?php
function my_module_menu() {
$items = array();
$items['my_module/form'] = array(
'title' => 'My form',
'page callback' => 'drupal_get_form',
'page arguments' => array('my_module_my_form'),
'access arguments' => array('access content'),
'description' => 'My form',
'type' => MENU_CALLBACK,
);
$items['my_module/edit'] = array(
'title' => t('Edit Name'),
'page callback' => 'drupal_get_form',
'page arguments' => array('my_module_edit'),
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
return $items;
}
function my_module_my_form($form_state) {
$form['first_name'] = array(
'#type' => 'textfield',
'#title' => t('First name'),
'#required' => TRUE, // Added
);
$form['last_name'] = array(
'#type' => 'textfield',
'#title' => t('Last name'),
'#required' => TRUE, // Added
);
$form['year_of_birth'] = array(
'#type' => 'textfield',
'#title' => ('Year of birth'),
'#description' => 'Format is "YYYY"',
);
// Adds a simple submit button that refreshes the form and clears its contents -- this is the default behavior for forms.
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Submit',
);
function my_module_edit($form, &$form_submit){
$form['Edit'] = array(
'#type' => 'Edit',
'#value' => 'Edit',
);
return $form;
}
function my_module_my_form_submit($form, &$form_state){
$firstName = $form_state['values']['fname'];
$lastName=$form_state['value']['lname'];
$yearofbirth = $form_state['values']['yearOfbirth'];
$query ="INSERT INTO `slideshow`.`mymoduledb`(`first_name`,`last_name`,`year_of_birth`) VALUES ('{$firstName}','{$lastName}','{$yearofbirth}')";
//$result=db_query($query);
if ($success = db_query($query)) {
// Tell the user that the employee has been saved.
drupal_set_message(t(' has been saved.'));
}else{ // If there's an error, $success will evaluate to FALSE, and the following code will execute.
drupal_set_message(t('There was an error saving your data. Please try again.'));
}
}
}
선생님 내가 드루팔와 PHP 내가 위의 링크를 이해하고 있지 않다 아주 새로운 오전. 개념을 이해하기위한 간단한 코드를 게시하는 것이 가능합니다 ........ 감사합니다 .... – SQA