You are here

function security_questions_selector_element in Security Questions 6.2

Same name and namespace in other branches
  1. 7.2 security_questions.pages.inc \security_questions_selector_element()

Helper function to generate a question selector and answer form element.

Parameters

$parent_name: The ID of the parent form element, used for the custom question field's ctools #dependency.

$account: (optional) The user whose questions/answers are being chosen.

$answer: (optional) An answer object to use as the default value.

Return value

A form element array.

1 call to security_questions_selector_element()
security_questions_user_form in ./security_questions.pages.inc
The user's security questions form.

File

./security_questions.pages.inc, line 21
User page callbacks for the security questions module.

Code

function security_questions_selector_element($parent_name, $account = NULL, $answer = NULL) {
  $form['question'] = array(
    '#type' => 'select',
    '#title' => t('Security question'),
    '#required' => TRUE,
    '#options' => security_questions_get_question_list($account),
    '#default_value' => isset($answer) ? $answer->sqid : NULL,
  );
  if (variable_get('security_questions_user_questions', FALSE)) {

    // This CTools approach is deprecated in D7 in favor of Form API #states.
    ctools_include('dependent');
    $form['question']['#options']['other'] = t('- CUSTOM - Enter your own question');
    $form['custom_question'] = array(
      '#type' => 'textfield',
      '#title' => t('Custom question'),
      '#dependency' => array(
        $parent_name . '-question' => array(
          'other',
        ),
      ),
      '#process' => array(
        'ctools_dependent_process',
      ),
    );
  }
  $form['answer'] = array(
    '#type' => 'textfield',
    '#title' => t('Answer'),
    '#required' => TRUE,
    '#default_value' => isset($answer) ? $answer->answer : '',
  );
  return $form;
}