hi all,

iam little bit new in drupal ...i hope anyone help me in my problem..?
i have a form that is supposed to submit to a page that shows some data from a table in db,

the problem is: i want to redirect my current page -when submittg the form - to the page which return data from db , i read alot on drupal API like drupal_submit_form and drupal_go_to() the second function need path where it is supposed to go but actually i didnot have any paths , i have a code in php code.

hope anyone help me plzzzzzzzz

thanks for advance

Comments

barrett’s picture

You'll need to define a path for the output page in your module's hook_menu (http://api.drupal.org/api/function/hook_menu) implementation. Then you can use the #redirect attribute (http://api.drupal.org/api/file/developer/topics/forms_api_reference.html...) in the form's FAPI definition.

amira’s picture

thank u Barrett ,

here is what i made ..............but no change

<?
function  request_block($op = 'list', $delta = 0, $edit = array()) 
{  

if ($op == "list")
 {
    // Generate listing of blocks from this module, for the admin/block page
    $block = array();
    $block[0]["info"] = t('Show Pending Requests');
    return $block;
  } 
   
else if ($op == 'view') 
{ 
  $block_content.='<form name="f1" action="" method="post">';
  
  $block_content.='User Name     <input type="text" name="username" value="'.$GLOBALS[user]->name.'"><br>';
  $block_content.='Vacation Date <input type="text" name="vacationdate" ><br>';
  $block_content.='Vacation Price<input type="text" name="vacationprice" ><br>';
  $block_content.='<input type="submit" value="OK" ><br><br>';
  $block_content .='<a href="'.$_SERVER['REQUEST_URI'].'&actionName=show">Show Ur Pending Requests</td>';
  $block_content.='<input type="hidden" value="insert" name="create">';

 
			if ($_REQUEST[create]=="insert") 
			{
			    $query = "insert into requests (name, v_date, v_price, status) values ('".$GLOBALS['user']->name."', '".$_REQUEST[vacationdate]."', '".$_REQUEST[vacationprice]."', 'pending')";
			     $queryResult =  db_query($query);
		         //drupal_set_message(t("drupal_get_form('f2')"));
			    if($queryResult) 
			    {
			      drupal_set_message(t("Created OK!!!"));
       		    }
					
		    }
			else if($_REQUEST[actionName]=="show")
			{
					
					//require_once(dirname(__FILE__)."/show.php");
					//drupal_get_form("f2");
					$query2 = "SELECT id, v_date, v_price FROM requests where name='".$GLOBALS['user']->name."'";
					$queryResult2 = db_query($query2);
			       // $block_content.='<form name="f2" id="f2" action="" method="post">';
					
					while ($arr =db_fetch_object($queryResult2)) 
					  {
					  
						$block_content .='<br><input type="textbox"  value="'.$arr->v_date.'" >';
						$block_content .='<input type="textbox"  value="'.$arr->v_price.'" ><br>';
						
					  }
					   $block_content.='</form>';
					 //  $block_content .='drupal_get_form("f2")';
			}		
			
   $block_content.='</form>';
   
   if ($block_content == '') 
		{    
			/* No content from a week ago.  If we return nothing, the block   
			 * doesn't show, which is what we want. 
			 */
			return;
		}

  // set up the block  
  $block = array();
  $block['subject'] = 'Show Pending Requests';  
  $block['content'] = $block_content;
 
  return $block;

}

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

  $items['request'] = array(
    'title' => 'pending requests',
    'description' => 'Listing of pending requests',
    'page callback' => 'request_page',
    'access arguments' => array('access content'),
    'type' => MENU_SUGGESTED_ITEM,
  );
  $items['page/request'] = array(
    'title' => 'RSS feed',
    'page callback' => 'page_request',
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
  );

  return $items;
  
  $form['#redirect'] = array('page/request', 'destination=node');


}

 ?>

any suggesstions..........?

thanks for advance

barrett’s picture

Ahhh...Well, there are a couple problems here. Lets start with your menu function. A return statement in a function halts processing of the function, so the $form... line you have in there will never be processed. The function will get to the return $items; line and then processing passes out of the function.

That aside, the $form['#redirect'] is meaningless in the way you're using it. First, it shouldn't be in the menu function. The menu has no reference to the form you're talking about. That line should go in the form definition function...which leads to the next problem. You're defining the form via plain old html in the block function instead of using the FAPI.

How to revamp it to use the FAPI would take some time. I'd suggest googling around for FAPI tutorials. You could also check out Pro Drupal Development and Learning Drupal 6 Module Development. Both of those have really good coverage of the FAPI.

Good luck

amira’s picture

thanks Barrett so much,
i tried checking some tutorials and that is what i get but i have a problem in show button which is i cannot see any of records that i tried to retrieve....so any help to do that...

thanks in advance

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,
  );
  return $items;
}

function request_form() {
  return drupal_get_form('request_my_form');
}

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' => ' Show Pending Requests',
  );

  $form['next'] = array(
    '#type' => 'submit',
    '#value' => 'submit',
  );
  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']['#id'] == 'edit-showp') 
      {
        $obj = db_fetch_object( db_query(
            "SELECT v_date FROM {requests}" ) );
        $form['requests'] = array(
            '#type' => 'textfield',
            '#title' => t('Pending Requests'),
            '#default_value' => $obj->v_date,
            '#size' => 20,
            '#maxlength' => 255
        );
        return $form;
        //$form_state['rebuild'] = TRUE;
      
        }
    
  
}