i have an employee table with fields like id, name, age and salary.
Iam showing the list of employee names in my custom module and when i click on an employee name, i have to show the edit form of that employee.
The employee names are given a link, as like:
<a href='".$base_url."/my_module/edit/".$employee->id."'>
and the corresponding menu path is configured as:
$items['my_module/edit/%'] = array(
'title' => t('My form'),
'description' => t('Edit employee'),
'page callback' => 'my_module_edit',
'access arguments' => array('access content'),
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
And when i click on the 5th employee name, the url would be: …./my_module/edit/5
So now my questions are:
- How can i get the id (5) of the employee from the url in my my_module_edit function ?
- How can i show the edit form of the employee, populating the fields (by querying with id) ?
For question 2: You have got it mixed up a bit, you don’t create a custom ‘page callback’ menu item for forms, you should use ‘drupal_get_form’ as the ‘page callback’ with the name of your form() function (my_module_employee_form) as the ‘page arguments’.
Then in the function my_module_employee_form() you generate the form and populate it, and in my_module_employee_form_submit() you read the values back and store them in the database.