hi all,
lhave a multistep form that works as follow..
1 - user enter values in some textboxes then click save button which redirect him to the same page and save these values in db (this step working perfect)
2 - in this form there is another button "view" that is supposed to redirect user to step2 which is a form that has all the records that are exist in db. as links (this is work perfect too)
3 - the final step i want user when he/she click to any of this records -links- he is supposed to redirect to a page which has the description of this record (sure from db)....here is the problem that i send the id of the record that user clicked to show the crossponding description in new form (step 3) but unfortunatly , it doesn't work as i explained.. coz i when i clicked the link i find "page not Found"...why ..?
here is my code..and i want anyone to check if the step 3 is working in a proper way or not..?
<?php
// $Id$
/**
* @file
* The theme system, which controls the output of Drupal.
*
* The theme system allows for nearly all output of the Drupal system to be
* customized by user themes.
*/
function request_menu() {
$items['request/form'] = array(
'title' => t('ADD New request'),
'page callback' => 'request_form',
'access arguments' => array('access content'),
'description' => t('ADD New request'),
'type' => MENU_CALLBACK,
);
$items['request/pending'] = array( //add the new menu item
'title' => t('Show Pending Request'),
'page callback' => 'request_form_2', //call new form function
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
$items['request/price'] = array( //add the new menu item
'title' => t('Show prices'),
'page callback' => 'request_form_3', //call new form function
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
return $items;
}
function request_form() {
return drupal_get_form('request_my_form');
}
function request_form_2() {
return drupal_get_form('show_pending_request');
}
function request_form_3() {
return drupal_get_form('show_price');
}
function request_my_form($form_state) {
$form['requestinfo'] = array(
'#type' => 'fieldset',
'#title' => t('Request Info'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['requestinfo']['first'] = array(
'#type' => 'textfield',
'#title' => t('Name'),
'#default_value' => $GLOBALS[user]->name, // changed
'#description' => "Please enter your name.",
'#size' => 20,
'#maxlength' => 20,
);
$form['requestinfo']['vdate'] = array(
'#type' => 'textfield',
'#title' => t('Vacation Date'),
'#default_value' => $form_state['values']['vdate'], // changed
'#description' => "Please enter Date.",
'#size' => 20,
'#maxlength' => 20,
);
$form['requestinfo']['vprice'] = array(
'#type' => 'textfield',
'#title' => t('Vacation Price'),
'#default_value' => $form_state['values']['vprice'], // changed
'#description' => "Please enter Price.",
'#size' => 20,
'#maxlength' => 20,
);
$form['clear'] = array(
'#type' => 'submit',
'#value' => 'Reset form',
'#validate' => array('my_module_my_form_clear'),
);
$form['showp'] = array(
'#type' => 'submit',
'#value' => 'view',
);
$form['next'] = array(
'#type' => 'submit',
'#value' => 'Save >>',
);
return $form;
}
function show_pending_request() {
$sql = db_query("SELECT v_date ,id FROM {requests} where name='".$GLOBALS[user]->name."'");
while ($obj = db_fetch_object($sql))
{
$options = array(
'query' => array('vid/'.$obj->id),
);
$form['request'][]=array(
'#value' => l($obj->v_date,'http://localhost/drupal?q=request/price&'.'vid/'.$obj->id),
);
}
return $form;
}
// form that show the description of the record depend on its id that i appended on the query string(vid)
function show_price() {
$sql = db_query("SELECT v_price FROM {requests} where id='".$_GET[vid]."'");
while ($obj = db_fetch_object($sql))
{
$form['request'][desk]=array(
'#value' => $obj->v_price,
);
}
return $form;
}
function request_my_form_new_name($form, &$form_state) {
$form_state['storage']['new_name'] = TRUE;
$form_state['rebuild'] = TRUE; // Will cause the default submit function
// to be skipped.
}
function request_my_form_clear($form, &$form_state) {
unset($form_state['values']); // ensures fields are blank after reset
// button is clicked
unset($form_state['storage']); // ensures the reset button removes the
// new_name part
$form_state['rebuild'] = TRUE;
}
function request_my_form_submit($form, &$form_state) {
// Handle page 1 submissions
if ($form_state['clicked_button']['#id'] == 'edit-next') {
$form_state['storage']['page_one_values'] = $form_state['values'];
db_query("INSERT INTO {requests} (name, v_date, v_price) VALUES ('%s','%s','%s' )",
$form_state['storage']['page_one_values']['first'],
$form_state['storage']['page_one_values']['vdate'],
$form_state['storage']['page_one_values']['vprice']); //page 1
drupal_set_message(t('Your form has been saved.'));
}
else if ( $form_state['clicked_button']['#value'] == 'view' ) {
drupal_goto($path = 'http://localhost/drupal?q=request/pending', $query = NULL, $fragment = NULL, $http_response_code = 302);
}
}
?>
thanks for advance