Drupal Form submit

1.3k views Asked by At

How could i sent the $first_name and $last_name variable values without attaching them in the url in the below example

    function my_module_my_form_submit($form, &$form_state) {
$first_name = $form_state['values']['first'];
$last_name = $form_state['values']['last'];

drupal_goto("/my_view/".$first_name."/".$last_name);

}

2

There are 2 answers

0
Raniel On

You can use a $_SESSION variable:

$_SESSION['first_name'] = $first_name;
$_SESSION['last_name'] = $last_name;

then get this values from other page.

0
AKS On

First, you should not call drupal_goto() in a form submit handler. drupal_goto() will send the location header immediately and exit the process, thus preventing the rest of the submit function from being executed.

If you want to process your form, do it in the submit handler. Drupal form API uses the same URL to render the form and as the target URL.

If you need to redirect user after the form submit, do as follows.

function my_module_my_form_submit($form, &$form_state) { // $form_state is passed by reference! {
 // .. Do submit handling here. 
 $form_state['redirect'] = 'my_view/'."$first_name/$last_name";
}

If you want to access them in in a latter step, store them in SESSION; See Raniel's answer.