register_form.inc in Lockr 7
Same filename and directory in other branches
Form handlers for registration.
File
include/register_form.incView source
<?php
/**
* @file
* Form handlers for registration.
*/
use Lockr\Exception\ClientException;
use Lockr\Exception\ServerException;
/**
* Returns the register form.
*/
function lockr_admin_register_form(&$form_state) {
$form = array();
$form['email'] = array(
'#type' => 'textfield',
'#title' => t('Email address'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Sign up'),
'#validate' => array(
'lockr_admin_register_validate',
),
'#submit' => array(
'lockr_admin_register_submit',
),
);
$next = isset($_GET['next']) ? $_GET['next'] : '/admin/config/system/keys';
$form_state['storage']['redirect'] = $next;
return $form;
}
/**
* Validate the register form.
*/
function lockr_admin_register_validate($form, &$form_state) {
if (!valid_email_address($form_state['values']['email'])) {
form_set_error('email', t('Please enter a valid email address'));
}
}
/**
* Submit the register form.
*/
function lockr_admin_register_submit($form, &$form_state) {
$values = $form_state['values'];
$next = $form_state['storage']['redirect'];
$name = variable_get('site_name');
try {
lockr_site_client()
->register($values['email'], null, $name);
} catch (ClientException $e) {
drupal_set_message(t('This email is already registered with Lockr. ' . 'Please login to register a new site.'));
drupal_goto('admin/config/system/lockr/login', array(
'query' => array(
'next' => $next,
'email' => $form_state['values']['email'],
),
));
} catch (ServerException $e) {
form_set_error('', t('An unknown error has occurred, please try again later.'));
}
drupal_set_message(t("That's it! You're signed up with Lockr; your keys can now be safely stored off-site."));
$form_state['redirect'] = $next;
}
Functions
Name | Description |
---|---|
lockr_admin_register_form | Returns the register form. |
lockr_admin_register_submit | Submit the register form. |
lockr_admin_register_validate | Validate the register form. |