function shurly_create_form in ShURLy 7
Same name and namespace in other branches
- 6 shurly.module \shurly_create_form()
The main form to create new short URLs.
2 string references to 'shurly_create_form'
- shurly_block_content_form in ./
shurly.module - Generate Shurly creation form for respective block
- shurly_menu in ./
shurly.module - Implements hook_menu().
File
- ./
shurly.module, line 414 - description http://www.youtube.com/watch?v=Qo7qoonzTCE
Code
function shurly_create_form($form, &$form_state) {
global $base_url;
$form['long_url'] = array(
'#title' => t('Enter a long URL to make short'),
'#type' => 'textfield',
'#maxlength' => 2048,
'#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"><--- ' . 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'])) {
if (module_exists('clipboardjs')) {
libraries_load('clipboard');
$form['result'] = array(
'#type' => 'container',
'#prefix' => '<div class="shurly-result">',
'#suffix' => '</div>',
'url' => theme('clipboardjs', array(
'text' => $form_state['storage']['shurly']['final_url'],
'alert_style' => 'tooltip',
'alert_text' => 'Copy was successful',
'button_label' => t('Copy'),
)),
);
$form['result']['url']['text']['#attributes']['class'] = array(
"inline",
);
$form['result']['url']['text']['#prefix'] = '<label class="inline">' . t('Your short URL:') . '</label>';
$form['result']['url']['button']['#suffix'] = '<div class="social"><a href="http://twitter.com?status=' . urlencode($form_state['storage']['shurly']['final_url']) . '">' . t('Create a Twitter message with this URL') . '</a></div>';
}
else {
$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 class="social"><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;
}