public function BotchaRecipe::apply in BOTCHA Spam Prevention 7.3
Same name and namespace in other branches
- 6.3 controller/recipe/botcha.recipe.controller.inc \BotchaRecipe::apply()
1 call to BotchaRecipe::apply()
- BotchaRecipeNoResubmit::apply in controller/
recipe/ botcha.recipe.controller.inc
1 method overrides BotchaRecipe::apply()
- BotchaRecipeNoResubmit::apply in controller/
recipe/ botcha.recipe.controller.inc
File
- controller/
recipe/ botcha.recipe.controller.inc, line 222 - Controller layer of the BotchaRecipe objects.
Class
- BotchaRecipe
- Abstract class to describe recipe data structure.
Code
public function apply(&$form, &$form_state) {
$this
->prepare($form, $form_state);
// Apply recipe to the concrete form.
// Add BOTCHA fields to the form.
$form_elements = $this
->generateFormElements();
foreach ($form_elements as $field_name => $field_properties) {
unset($field_properties['!valid_token']);
$form[$field_name] = $field_properties;
if ($this->method == 'build_id_submit') {
// Save submitted values in our stash for later use in _validate,
// as we have to reset them here at _form_alter stage.
// It won't be possible to reset after validation as there is no
// reliable mechanism in Form API, i.e. form_set_value() does not
// change rendered form and form errors disable whole 'rebuild' business.
if (isset($_POST[$field_name])) {
$form_state['botcha_submit_values'][$field_name] = $_POST[$field_name];
}
if (isset($field_properties['#default_value'])) {
// Reset our controls to defaults here (as explained above).
$form[$field_name]['#value'] = $field_properties['#default_value'];
$form_state['post'][$field_name] = $field_properties['#default_value'];
$_POST[$field_name] = $field_properties['#default_value'];
}
}
else {
//unset($field_properties['!valid_token']);
}
}
}