[development] editing form and submitting values to database in custom module not working

mahesh gajabar mahesh143an at gmail.com
Sat Jan 8 11:42:08 UTC 2011


Hi

I have wrote custom module for showing values in html format table. I have
delete and edit action for every row. My delete function working but edit
function not working .Whats wrong with code. What i need to do corrections
for it.For editing the form i NEED TO BE get default values in form that too
not getting.please help me guys

*
<?php*

function doctor_menu() {
$items = array();

$items['doctor'] = array(
'title' => t('Doctors'),
'page callback' => 'doctors_list',
'access arguments' => array('access doctor'),
'type' => MENU_NORMAL_ITEM );
$items['doctor/delete/%doctor_user'] = array(
'title' => t('Delete doctor'),
'page callback' => 'drupal_get_form',
'page arguments' => array('doctor_delete_confirm', 2),
'access arguments' => array('access doctor'),
'type' => MENU_CALLBACK, );
$items['doctor/edit/%doctor_user'] = array(
'title' => t('Edit Form'),
'page callback' => 'drupal_get_form',
'page arguments' => array('doctor_edit_confirm', 2),
'access arguments' => array('access doctor'),
'type' => MENU_NORMAL_ITEM,
);return $items;
}
function doctors_list() {
$header = array(t('Doctor Name'), t('Gender'), t('Status'), t('Action'));
$query = "SELECT * FROM {doctor}";
$rs = db_query($query);
$row = array();
if ($rs) {
while ($data = db_fetch_object($rs)) {
$gender = $data->gender;
$status = $data->status ;
$row[] = array(stripslashes(ucwords($data->firstname)) . ' ' .
stripslashes(ucwords($data->lastname)), $gender, $status,
"doctorid}'>" . t('Edit') . " | doctorid}'>" . t('Delete') . "");
}}
$str .= theme_table($header, $row);
return $str;
}
function doctor_user_load($doctorid) {
$query = "SELECT * FROM {doctor} WHERE doctorid = %d";
$rs = db_query($query, $doctorid);

if ($rs) {
while ($data = db_fetch_object($rs)) {
return $data;
}}
return FALSE;
}
function doctor_delete_confirm(&$form_state, $doctor) {
$form['_doctor'] = array(
'#type' => 'value',
'#value' => $doctor,);

return confirm_form($form,t('Are you sure you want to delete this doctor?'),
isset($_GET['destination']) ? $_GET['destination'] : "doctor",t('This action
cannot be undone.'),t('Delete'),t('Cancel'));}

function doctor_delete_confirm_submit($form, &$form_state) {
$form_values = $form_state['values'];
if ($form_state['values']['confirm']) {
$doctor = $form_state['values']['_doctor'];

$query = "DELETE FROM {doctor} where doctorid=$doctor>doctorid";
$rs = db_query($query);
drupal_set_message(t('Doctor has been deleted successfully.'));}
drupal_goto("doctor");
}
function doctor_edit_confirm(&$form_state,$doctor){

$form = array();
$form['firstname']=array(
'#title'=>t('First Name'),
'#type'=>'textfield',
'#default_value' => $firstname );
$form['lastname']=array(
'#title'=>t('Last Name'),
'#type'=>'textfield',
'#default_value' => $lastname);
$form['gender']=array(
'#title'=>t('Gender'),
'#type'=>'radios','#options' => array(t('male'), t('female')),
'#default_value' => male);
$form['status']=array(
'#title'=>t('Status'),
'#type'=>'radios',
'#default_value' => active,
'#options' => array(t('active'), t('inactive')));
return confirm_form($form,t(''),
isset($_GET['destination']) ? $_GET['destination'] : "doctor",
t(''),
t('Edit'),
t('Cancel'));}

function doctor_edit_confirm_submit($form, &$form_state)
{
$form_values = $form_state['values'];
if ($form_state['values']['confirm']) {
$doctor = $form_state['values']['_doctors'];
$query = "UPDATE {doctor} WHERE doctorid='$doctor->doctorid'";
} drupal_goto("doctor");}

*MAHESH GAJABAR
Software Developer
FrontalRain Technologies,Bengaluru*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20110108/8eaa6a05/attachment.html 


More information about the development mailing list