You are here

function guestbook_form_entry_form in Guestbook 7.2

Same name and namespace in other branches
  1. 5.2 guestbook.module \guestbook_form_entry_form()
  2. 5 guestbook.module \guestbook_form_entry_form()
  3. 6.2 guestbook.module \guestbook_form_entry_form()
  4. 6 guestbook.module \guestbook_form_entry_form()

Form builder function for guestbook post form.

2 string references to 'guestbook_form_entry_form'
guestbook_form_entry in ./guestbook.module
Retrieve a guestbook post form.
guestbook_page in ./guestbook.module
Output a guestbook page; menu callback.

File

./guestbook.module, line 497

Code

function guestbook_form_entry_form($form, $form_state, $uid, $display = '', $entry_id = NULL) {
  global $user;
  $entry = array();
  if (isset($entry_id) && _guestbook_access('moderate', $uid) && user_access('moderate own guestbook')) {
    $entry = db_query("SELECT * FROM {guestbook} WHERE id = :id", array(
      ':id' => $entry_id,
    ))
      ->fetchAssoc();
  }
  $form = array();
  if (!empty($entry)) {
    $form['entry_id'] = array(
      '#type' => 'value',
      '#value' => $entry['id'],
    );
    $form['author'] = array(
      '#type' => 'value',
      '#value' => $entry['author'],
    );

    // Re-route form submission to guestbook entry edit form submit handler.
    $form['#submit'] = array(
      'guestbook_form_entry_form_edit_submit',
    );
  }

  // Fields for anonymous users.
  $anonymous_fields_access = !$user->uid || isset($entry['author']) && $entry['author'] == 0;
  $anonymous_fields = (array) variable_get('guestbook_anonymous_fields', array(
    'email',
    'website',
  ));
  $form['anonname'] = array(
    '#type' => 'textfield',
    '#title' => t('Name'),
    '#required' => TRUE,
    '#default_value' => !empty($entry['anonname']) ? $entry['anonname'] : '',
    '#size' => 32,
    '#maxlength' => 64,
    '#access' => $anonymous_fields_access,
  );
  $form['anonemail'] = array(
    '#type' => 'textfield',
    '#title' => t('E-mail'),
    '#default_value' => !empty($entry['anonemail']) ? $entry['anonemail'] : '',
    '#size' => 32,
    '#maxlength' => 128,
    '#access' => $anonymous_fields_access && in_array('email', $anonymous_fields),
  );
  $form['anonwebsite'] = array(
    '#type' => 'textfield',
    '#title' => t('Homepage'),
    '#default_value' => !empty($entry['anonwebsite']) ? $entry['anonwebsite'] : '',
    '#size' => 32,
    '#maxlength' => 128,
    '#access' => $anonymous_fields_access && in_array('website', $anonymous_fields),
  );
  $form['message'] = array(
    '#type' => 'text_format',
    '#title' => t('Message'),
    '#rows' => GUESTBOOK_TEXTAREA_ROWS,
    '#required' => TRUE,
    '#default_value' => !empty($entry['message']) ? $entry['message'] : '',
    '#format' => isset($entry['message_format']) ? $entry['message_format'] : NULL,
  );
  $form['status'] = array(
    '#type' => 'checkbox',
    '#title' => t('Published'),
    '#default_value' => isset($entry['status']) ? $entry['status'] : variable_get('guestbook_entry_default_status', 1),
    '#access' => !empty($entry),
  );
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Send'),
  );
  $form['uid'] = array(
    '#type' => 'value',
    '#value' => $uid,
  );
  if (!empty($entry)) {

    // Need to explicitly check for moderate when editing an existing post,
    // because FAPI will output a WSOD (NULL) otherwise.
    $form['#access'] = _guestbook_access('moderate', $uid) ? TRUE : FALSE;
  }
  else {
    $form['#access'] = in_array(_guestbook_access('post', $uid), array(
      'allowed',
      'own guestbook',
    ));
  }
  if (variable_get('guestbook_form_location', 'above') == 'separate page') {
    $form['#redirect'] = !empty($_GET['destination']) ? $_GET['destination'] : guestbook_path($uid);
  }
  $form['display'] = array(
    '#type' => 'value',
    '#value' => $display,
  );
  return $form;
}