You are here

function fb_user_post_add_form in Drupal for Facebook 5

A form which helps a facebook user either register a new local drupal account or synchronize facebook account with an existing account. Really, all we do is redirect the user to the login or registration forms.

File

./fb_user.module, line 149
This module allows Drupal user records to be associated with Facebook user ids. It can create local user accounts when Facebook users visit an application's canvas pages.

Code

function fb_user_post_add_form() {
  global $fb, $fb_app, $user;

  // This form only works on canvas pages.
  if (!$fb_app) {
    drupal_access_denied();
    exit;
  }

  // And if the user's account is recognized, we can skip this.
  if ($user->uid && FALSE) {
    drupal_goto("<front>");
    exit;
  }

  // Substitutions for translation
  $t = array(
    '%sitename' => variable_get('site_name', t('this website')),
    '%appname' => $fb_app->title,
  );
  drupal_set_title(t('Welcome to %appname', $t));
  $parents = array(
    'redirect',
  );

  // Could use 'radios' type, but using 'radio' is more flexible.
  $form['redirect']['user/login'] = array(
    '#type' => 'radio',
    '#title' => t('I already have an account on %sitename', $t),
    '#description' => t('You will be prompted for your password.', $t),
    '#return_value' => 'user/login',
    '#parents' => $parents,
  );
  $form['redirect']['user/register'] = array(
    '#type' => 'radio',
    '#title' => t('Complete my registration now', $t),
    '#description' => t('You will be asked for additional information and given a new password.', $t),
    '#return_value' => 'user/register',
    '#parents' => $parents,
    '#default_value' => 'user/register',
  );
  $form['redirect']['frontpage'] = array(
    '#type' => 'radio',
    '#title' => t('I will register later', $t),
    '#description' => t('Use this application without registering on %sitename.', $t),
    '#return_value' => '<front>',
    '#parents' => $parents,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Continue'),
  );
  return $form;
}