You are here

function pollim_edit_form in Poll Improved 7

Form callback: create or edit a pollim.

Parameters

$pollim: The pollim object to edit or for a create form an empty pollim object with only a pollim type defined.

1 string reference to 'pollim_edit_form'
pollim_form_wrapper in ./pollim.admin.inc
Form callback wrapper: create or edit a pollim.

File

./pollim.admin.inc, line 168
Pollim editing UI.

Code

function pollim_edit_form($form, &$form_state, $pollim) {

  // Add the default field elements.
  $form['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Poll name'),
    '#default_value' => isset($pollim->name) ? $pollim->name : '',
    '#maxlength' => 255,
    '#required' => TRUE,
    '#weight' => -5,
  );

  // Add the field related form elements.
  $form_state['pollim'] = $pollim;
  field_attach_form('pollim', $pollim, $form, $form_state);
  $form['actions'] = array(
    '#type' => 'container',
    '#attributes' => array(
      'class' => array(
        'form-actions',
      ),
    ),
    '#weight' => 400,
  );

  // We add the form's #submit array to this button along with the actual submit
  // handler to preserve any submit handlers added by a form callback_wrapper.
  $submit = array();
  if (!empty($form['#submit'])) {
    $submit += $form['#submit'];
  }
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save poll'),
    '#submit' => $submit + array(
      'pollim_edit_form_submit',
    ),
  );
  if (!empty($pollim->name)) {
    $form['actions']['delete'] = array(
      '#type' => 'submit',
      '#value' => t('Delete poll'),
      '#suffix' => l(t('Cancel'), 'admin/content/pollims'),
      '#submit' => $submit + array(
        'pollim_form_submit_delete',
      ),
      '#weight' => 45,
    );
  }

  // We append the validate handler to #validate in case a form callback_wrapper
  // is used to add validate handlers earlier.
  $form['#validate'][] = 'pollim_edit_form_validate';
  return $form;
}