You are here

function formdefaults_form_alter in Form Defaults 5.3

Same name and namespace in other branches
  1. 8 formdefaults.module \formdefaults_form_alter()
  2. 5 formdefaults.module \formdefaults_form_alter()
  3. 5.2 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 122

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
  $savedform = formdefaults_getform($formid);
  _formdefaults_addon_fields($savedform, $form);

  //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;
  }
  if ($savedform) {
    foreach ($form as $fieldname => $value) {
      formdefaults_alterform($formid, $fieldname, $form[$fieldname], $savedform);
    }
  }
  if ($enabled) {
    $form['formdefaults_edit_form'] = array(
      '#type' => 'markup',
      '#weight' => -10,
      '#value' => '<p>' . l('[' . t('edit form') . ']', 'formdefaults/' . $formid) . '</p>',
    );
  }
}