You are here

function formdefaults_form_alter in Form Defaults 5.2

Same name and namespace in other branches
  1. 8 formdefaults.module \formdefaults_form_alter()
  2. 5.3 formdefaults.module \formdefaults_form_alter()
  3. 5 formdefaults.module \formdefaults_form_alter()
  4. 6.2 formdefaults.module \formdefaults_form_alter()
  5. 6 formdefaults.module \formdefaults_form_alter()
  6. 7 formdefaults.module \formdefaults_form_alter()

implements hook_form_alter

File

./formdefaults.module, line 95

Code

function formdefaults_form_alter($formid, &$form) {
  $enabled = $_SESSION['formdefaults_enabled'] && $formid != 'formdefaults_edit';

  // Add a header and a footer to all forms for instructions
  $form['formdefaults_header'] = array(
    '#type' => 'markup',
    '#value' => '',
    '#weight' => -10,
  );
  $form['formdefaults_footer'] = array(
    '#type' => 'markup',
    '#value' => '',
    '#weight' => 10,
  );

  //If the user has the right privs, add the links to alter the form
  $formfieldsarray = array();
  if (user_access('change form labels') && $enabled) {
    $forms = $_SESSION['formdefaults_forms'];
    foreach ($form as $fieldname => $value) {
      _formdefaults_get_field($formid, $fieldname, $form[$fieldname], $formfieldsarray);
    }
    $forms[$formid] = $formfieldsarray;
    $_SESSION['formdefaults_forms'] = $forms;
  }
  $savedform = formdefaults_getform($formid);
  if ($savedform) {
    foreach ($form as $fieldname => $value) {
      formdefaults_alterform($formid, $fieldname, $form[$fieldname], $savedform);
    }
  }
}