How to access data from a page on a form hook? I have a page that has a $_GET and I would like to use that value on the form that is used on that page, but I do not know how to pass a variable to that form for use. usually I can just get the data from elsewhere, but the $_GET is NULL when I run it in the form itself.

function mymodule_menu() {

   $items = array();

   $items['sample'] = array(
    'title' =&gt; 'Title',
    'description' =&gt; '',
    'page callback' =&gt; 'mymodule_page',
    'access arguments' =&gt; array('access content')
  );
}

function mymodule_page() {
    $variable = $_GET['variable'];
    return theme('mymodule_page', array(
       'form' =&gt; drupal_get_form('mymodule_page_form'),
       'variable' =&gt; $variable
    ));
}
function mymodule_page_form(){
    var_dump($variable); &lt;-- not defined.
}


I tried variable_get and variable_set, but it's not reliable because it seems to hold values for a while.
By default variables defined in one function aren't available in any other functions (see PHP: Variable scope), which is why your variable is undefined in the form function.

You can declare $variable as a global (see the link above) to make it available in both your functions:

function mymodule_page() {
    global $variable;
    $variable = $_GET['variable'];
    return theme('mymodule_page', array(
       'form' =&gt; drupal_get_form('mymodule_page_form'),
       'variable' =&gt; $variable
    ));
}
function mymodule_page_form(){
    global $variable;
    var_dump($variable);
}


But to be honest there's no good reason why $_GET would be empty when it reaches your form function, so it might be worth seeing if you can find out why that's happening.