You are here

function spamicide_pre_render_place_spamicide in Spamicide 7

Same name and namespace in other branches
  1. 5 spamicide.module \spamicide_pre_render_place_spamicide()

Place the spamicide field just before the submit button

@todo figure out how to make this work

Parameters

$form_id:

$form:

1 string reference to 'spamicide_pre_render_place_spamicide'
spamicide_form_alter in ./spamicide.module
Implements hook_form_alter().

File

./spamicide.module, line 454
This module provides yet another tool to eliminate spam.

Code

function spamicide_pre_render_place_spamicide(&$form) {
  module_load_include('inc', 'spamicide');

  // search the weights of the buttons in the form
  $button_weights = array();
  foreach (element_children($form) as $key) {
    if ($key == 'buttons' || isset($form[$key]['#type']) && $form[$key]['#type'] == 'submit') {
      $button_weights[] = $form[$key]['#weight'];
    }
  }
  if ($button_weights) {

    // set the weight of the Spamicide element a tiny bit smaller than the lightest button weight
    // (note that the default resolution of #weight values is 1/1000 (see drupal/includes/form.inc))
    $first_button_weight = min($button_weights);
    $spamicide_field = _spamicide_get_field($form_id);
    if ($spamicide_field) {
      $form[$spamicide_field]['#weight'] = $first_button_weight - 0.5 / 1000.0;
    }
    else {
      $form['spamicide']['#weight'] = $first_button_weight - 0.5 / 1000.0;
    }

    // make sure the form gets sorted before rendering
    unset($form['#sorted']);
  }
  return $form;
}