You are here

function formdefaults_form_alter in Form Defaults 6

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. 5.2 formdefaults.module \formdefaults_form_alter()
  5. 6.2 formdefaults.module \formdefaults_form_alter()
  6. 7 formdefaults.module \formdefaults_form_alter()

implements hook_form_alter

File

./formdefaults.module, line 93

Code

function formdefaults_form_alter(&$form, $form_state, $formid) {
  $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' => -50,
  );
  $form['formdefaults_footer'] = array(
    '#type' => 'markup',
    '#value' => '',
    '#weight' => 50,
  );

  //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);
    }
  }
}