function shorten_form_shorten in Shorten URLs 6
Same name and namespace in other branches
- 7.2 shorten.module \shorten_form_shorten()
- 7 shorten.module \shorten_form_shorten()
Builds a form which allows shortening of a URL via the UI.
1 string reference to 'shorten_form_shorten'
- shorten_form_display in ./
shorten.module - Displays the Shorten form.
File
- ./
shorten.module, line 399 - Shortens URLs via external services.
Code
function shorten_form_shorten(&$form_state) {
$form['#cache'] = TRUE;
drupal_add_js(drupal_get_path('module', 'shorten') . '/shorten.js');
//Form elements between ['opendiv'] and ['closediv'] will be refreshed via AHAH on form submission.
$form['opendiv'] = array(
'#value' => '<div id="shorten_replace">',
);
if (!isset($form_state['storage'])) {
$form_state['storage'] = array(
'step' => 0,
);
}
if (isset($form_state['storage']['short_url'])) {
// This whole "step" business keeps the form element from being cached.
$form['shortened_url_' . $form_state['storage']['step']] = array(
'#type' => 'textfield',
'#title' => t('Shortened URL'),
'#default_value' => $form_state['storage']['short_url'],
'#size' => 25,
'#attributes' => array(
'class' => 'shorten-shortened-url',
),
);
}
$form['url_' . $form_state['storage']['step']] = array(
'#type' => 'textfield',
'#title' => t('URL'),
'#default_value' => '',
'#required' => TRUE,
'#size' => 25,
'#maxlength' => 2048,
'#attributes' => array(
'class' => 'shorten-long-url',
),
);
//Form elements between ['opendiv'] and ['closediv'] will be refreshed via AHAH on form submission.
$form['closediv'] = array(
'#value' => '</div>',
);
$last_service = NULL;
if (isset($form_state['storage']['service'])) {
$last_service = $form_state['storage']['service'];
}
$service = _shorten_service_form($last_service);
if (is_array($service)) {
$form['service'] = $service;
}
$form['shorten'] = array(
'#type' => 'submit',
'#value' => t('Shorten'),
'#ahah' => array(
'path' => 'shorten/js',
'wrapper' => 'shorten_replace',
'effect' => 'fade',
'method' => 'replace',
),
);
return $form;
}