function trick_question_admin_form in Trick Question 7
Same name and namespace in other branches
- 6 trick_question.module \trick_question_admin_form()
Create the main form
1 string reference to 'trick_question_admin_form'
- trick_question_menu in ./
trick_question.module - Implementation of hook_menu().
File
- ./
trick_question.module, line 66 - trick_question.module - Main file for trick question module
Code
function trick_question_admin_form() {
$form = array();
// What question to ask
$form['question'] = array(
'#type' => 'textfield',
'#size' => 120,
'#title' => t('Question'),
'#description' => t('Ask this question when showing the forms.'),
'#default_value' => variable_get('trick_question_question', ''),
'#required' => TRUE,
);
// What answer to give
$form['answer'] = array(
'#type' => 'textfield',
'#size' => 10,
'#title' => t('Answer'),
'#description' => t('Only allow submissions with this answer (letter case is ignored).'),
'#default_value' => variable_get('trick_question_answer', ''),
'#required' => TRUE,
);
// Get the explanation
$explanation = variable_get('trick_question_explanation', '');
// Set it to default if it's not empty
$explanation = $explanation == '' ? t('Yes, this is a trick question and easy to answer.<br />We ask it because spam bots are too stupid to answer correctly, while humans are not.') : $explanation;
// Save it just in case the user just emptied it
variable_set('trick_question_explanation', $explanation);
// What question to ask
$form['explanation'] = array(
'#type' => 'textarea',
'#title' => t('Explanation'),
'#description' => t('The explanation to show to the user. Enter <none> for no explanation or leave empty for default explanation.'),
'#default_value' => $explanation,
);
// Make a nice fieldset for the checkboxes
$form['forms'] = array(
'#type' => 'fieldset',
'#title' => t('Forms'),
'#suffix' => '<p>' . t('You can control <a href="!url">trick question per role using permissions</a>.', array(
'!url' => url('admin/people/permissions', array(
'fragment' => 'module-trick_question',
)),
)) . '</p>',
);
// Get the content types
$node_types = node_type_get_types();
foreach ($node_types as $node_type => $details) {
$options[$node_type . '_node_form'] = t('!name (!type)', array(
'!name' => $details->name,
'!type' => $node_type,
));
// Each node type has its own comment form ID in D7
$options['comment_node_' . $node_type . '_form'] = t('Comments to !name', array(
'!name' => $details->name,
));
}
// Other forms relevant
$options['user_register_form'] = t('User registration');
$forms = variable_get('trick_question_forms', array());
// Create checkboxes
$form['forms']['forms'] = array(
'#type' => 'checkboxes',
// '#title' => t('Forms'),
'#description' => t('Add a trick question to the selected forms.'),
'#options' => $options,
'#default_value' => $forms,
);
// What question to ask
$form['forms']['form_ids'] = array(
'#type' => 'textarea',
'#title' => t('Other form ID\'s'),
'#description' => t('You can manually add the Drupal ID of any form you want to equip it with a Trick Question. Write one ID on each line.'),
'#default_value' => variable_get('trick_question_form_ids', ''),
);
// Buttons
$form['buttons']['save'] = array(
'#type' => 'submit',
'#value' => t('Save'),
'#weight' => 140,
);
$form['buttons']['cancel'] = array(
'#type' => 'markup',
'#value' => l(t('Cancel'), 'admin/settings'),
'#weight' => 150,
);
return $form;
}