You are here

function formdefaults_form_alter in Form Defaults 7

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

implements hook_form_alter

File

./formdefaults.module, line 119

Code

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

  //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' => -50,
      '#markup' => '<p>' . l('[' . t('edit form') . ']', 'formdefaults/' . $formid) . '</p>',
    );
  }

  //drupal_set_message('<pre>'. print_r($form,1) .'</pre>');
}