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

Randy Fay randy at randyfay.com
Sat Jan 8 13:08:09 UTC 2011


I encourage you to start with a working example and build from there. There
are several examples in the Form Example in Examples project (
http://drupal.org/project/examples), and there are examples throughout core
that you can look at.

In addition, focus on learning how to debug so you can solve these yourself.
http://randyfay.com/debugging_drupal may be useful to you, and the Devel
module with its dsm() function is widely used by people to figure out what's
going on in situations like this.

This is a very helpful group, but they won't (usually) help you debug your
code or learn the basics of Drupal development.

-Randy

On Sat, Jan 8, 2011 at 5:42 AM, mahesh gajabar <mahesh143an at gmail.com>wrote:

> 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*
>
>
>
>


-- 
Randy Fay
Drupal Module and Site Development
randy at randyfay.com
+1  970.462.7450
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20110108/7e0eb284/attachment.html 


More information about the development mailing list