You are here

function shurly_create_form in ShURLy 6

Same name and namespace in other branches
  1. 7 shurly.module \shurly_create_form()

The main form to create new short URLs.

2 string references to 'shurly_create_form'
shurly_block in ./shurly.module
shurly_menu in ./shurly.module
Implementation of hook_menu()

File

./shurly.module, line 178
description http://www.youtube.com/watch?v=Qo7qoonzTCE

Code

function shurly_create_form($form_state) {
  global $base_url;
  $form['long_url'] = array(
    '#title' => t('Enter a long URL to make short'),
    '#type' => 'textfield',
    '#maxlength' => 255,
    '#default_value' => isset($form_state['storage']['shurly']['long_url']) ? $form_state['storage']['shurly']['long_url'] : (isset($_GET['url']) ? $_GET['url'] : 'http://'),
    '#attributes' => array(
      'tabindex' => 1,
    ),
  );
  $short_default = user_access('Enter custom URLs') ? isset($form_state['storage']['shurly']['short_url']) ? $form_state['storage']['shurly']['short_url'] : '' : '';
  $form['short_url'] = array(
    '#type' => 'textfield',
    '#size' => 6,
    '#field_prefix' => variable_get('shurly_base', $base_url) . '/',
    '#field_suffix' => ' <span class="shurly-choose">&lt;--- ' . t('create custom URL') . '</span>',
    '#default_value' => $short_default,
    '#access' => user_access('Enter custom URLs'),
    '#attributes' => array(
      'tabindex' => 2,
    ),
  );
  if (isset($form_state['storage']['shurly']['final_url'])) {
    $form['result'] = array(
      '#type' => 'textfield',
      '#size' => 30,
      '#value' => $form_state['storage']['shurly']['final_url'],
      '#prefix' => '<div class="shurly-result">',
      '#suffix' => '</div>',
      '#field_prefix' => t('Your short URL: '),
      '#field_suffix' => ' <div id="shurly-copy-container" style="position:relative;"><div id="shurly-copy">' . t('copy') . '</div></div>
      <div><a href="http://twitter.com?status=' . urlencode($form_state['storage']['shurly']['final_url']) . '">' . t('Create a Twitter message with this URL') . '</a></div>',
    );
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Shrink it!'),
    '#attributes' => array(
      'tabindex' => 3,
    ),
  );
  unset($form_state['storage']['shurly']);
  return $form;
}