You are here

function spamicide_field_place_field in Spamicide 6

Place the spamicide field just before the submit button

@todo figure out how to make this work

Parameters

$form_id:

$form:

1 call to spamicide_field_place_field()
spamicide_form_alter in ./spamicide.module
Implementation of hook_form_alter

File

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

Code

function spamicide_field_place_field(&$form, $form_id) {

  // 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') {
      if (!isset($form[$key]['#weight'])) {

        /*
         * forcing the issue of button weights
         * Setting a weight if there isn't one
         */
        $form[$key]['#weight'] = 1;
      }
      $button_weights[] = ++$form[$key]['#weight'];
    }
  }
  if (!empty($button_weights)) {

    /*
     * forcing the issue of button weights
     * push them all down 1
     */
    $spamicide_weight = min($button_weights) - 1;
    $spamicide_field = _spamicide_get_field($form_id);
    if ($spamicide_field) {
      $form[$spamicide_field]['#weight'] = $spamicide_weight;
    }
    else {
      $form['spamicide']['#weight'] = $spamicide_weight;
    }

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