updatedhow to set default value in a form field got from another page(form)? All,

What I want to do:
On the Home page, I have an input field in which a user can insert their invite code, the invite code gets validated via ajax and if correct, popups the registration form. Its important that the user cannot get access to the registration form without the correct invite code. How can I bullet proof this concept into my Drupal7 install? I am using Regcode module for registration purpose.

The problem I have is that if the user knows the address to the registration form, they can merely enter that into the browser's address bar and register without having to gain an invite code.

One solution I thought was that the invite code is needed on the actual registration form as well, so if they do access the form via the browser's address bar, they will still need to input the invite code. However, if they already did place the invite code in the input field (on the Home page), it would automatically populate the invite code field in the registration form. 

What problem I am facing:
Im not sure how to go about transferring the invite code (which the user inserted) into the registration form that pops up upon validation. 
The form(single field) on the front page is written by myself inside a block.

Here i am confused how to take the form value to the registration form and how to get the value of field and after getting how to set the value as default in the regcode text field.

 &lt;form method="GET" action="?????"&gt;&lt;/form&gt;


the modulea's part which alter the registration form is as follows

 function regcode_form_user_register_form_alter(&amp;$form, &amp;$form_state) {
  $code_optional = variable_get('regcode_optional', FALSE);
  $account = $form['#user'];

  $form['regcode']['regcode_code'] = array(
    '#type' =&gt; 'textfield',
    '#title' =&gt; variable_get('regcode_field_title', t('Registration Code')),
    '#description' =&gt; variable_get('regcode_field_description', t('Please enter your registration code.')),

    '#default_value' =&gt; ???????????,

    '#required' =&gt; !($code_optional || user_access('administer users')),
    '#element_validate' =&gt; array('regcode_code_element_validate'),
  );
  // Capture the code from the url and inject it into the registration form
  if (isset($_GET['regcode'])) {
    $form['regcode']['regcode_code']['#value']       = check_plain($_GET['regcode']);
    $form['regcode']['regcode_code']['#description'] = NULL;
    $form['regcode']['regcode_code']['#disabled']    = TRUE;
  }
}


i Hope, its understandable now
Drupal doesn't store the form state between forms, so you will need to do that yourself.

In this case I would use the session variable since you want to save it per user, but not permanently.

To do this you will need to add a custom submit handler to the form if you form is not created by you, this can be done with hook_form_alter

Then you can save the value you want to save in the session variable something like

 $_SESSION['my_value'] = $value;


should do the trick, then you can set the value in the form, either directly if you control it or via form alter.

That the form value is gotten from or is to be set to a field doesn't change things. The form field structure is a little more verbose, but the way to do it is pretty much the same.