You are here

request_form.inc in Lockr 7

Form handlers for the certificate request form.

File

include/request_form.inc
View source
<?php

/**
 * @file
 * Form handlers for the certificate request form.
 */

/**
 * Returns the certificate request form.
 */
function lockr_admin_request_form() {
  $form = array();
  $form['email'] = array(
    '#type' => 'textfield',
    '#title' => t('Email address'),
  );
  $form['partner'] = array(
    '#type' => 'textfield',
    '#title' => t('Hosting provider'),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Request certificate'),
    '#validate' => array(
      'lockr_admin_request_validate',
    ),
    '#submit' => array(
      'lockr_admin_request_submit',
    ),
  );
  return $form;
}

/**
 * Validate the certificate request form.
 */
function lockr_admin_request_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 certificate request form.
 */
function lockr_admin_request_submit($form, &$form_state) {
  $values = $form_state['values'];
  $ch = curl_init('https://lockr.io/api/v2/request-certificate');
  curl_setopt_array($ch, array(
    CURLOPT_POST => TRUE,
    CURLOPT_POSTFIELDS => array(
      'email' => $values['email'],
      'partner' => $values['partner'],
    ),
  ));
  curl_exec($ch);
  variable_set('lockr_request', TRUE);
  drupal_set_message(t('Thank you for letting us know! ' . "We'll email you shortly with further instructions."));
}

Functions

Namesort descending Description
lockr_admin_request_form Returns the certificate request form.
lockr_admin_request_submit Submit the certificate request form.
lockr_admin_request_validate Validate the certificate request form.