You are here

function guestbook_form_entry_form in Guestbook 5.2

Same name and namespace in other branches
  1. 5 guestbook.module \guestbook_form_entry_form()
  2. 6.2 guestbook.module \guestbook_form_entry_form()
  3. 6 guestbook.module \guestbook_form_entry_form()
  4. 7.2 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 432

Code

function guestbook_form_entry_form($uid, $display = '', $entry_id = NULL) {
  global $user;
  $entry = array();
  if (isset($entry_id) && _guestbook_access('moderate', $uid) && user_access('moderate own guestbook')) {
    $entry = db_fetch_array(db_query("SELECT * FROM {guestbook} WHERE id = %d", $entry_id));
  }
  $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' => array(),
    );
  }
  if ($user->uid == 0 || isset($entry['author']) && $entry['author'] == 0) {

    // fields for anonymous poster
    $form['anonname'] = array(
      '#type' => 'textfield',
      '#title' => t('Name'),
      '#size' => 32,
      '#maxlength' => 64,
      '#required' => TRUE,
      '#default_value' => !empty($entry['anonname']) ? $entry['anonname'] : '',
    );
    $anonymous_fields = (array) variable_get('guestbook_anonymous_fields', array(
      'email',
      'website',
    ));
    if (in_array('email', $anonymous_fields)) {
      $form['anonemail'] = array(
        '#type' => 'textfield',
        '#title' => t('E-mail'),
        '#size' => 32,
        '#maxlength' => 128,
        '#default_value' => !empty($entry['anonemail']) ? $entry['anonemail'] : '',
      );
    }
    if (in_array('website', $anonymous_fields)) {
      $form['anonwebsite'] = array(
        '#type' => 'textfield',
        '#title' => t('Homepage'),
        '#size' => 32,
        '#maxlength' => 128,
        '#default_value' => !empty($entry['anonwebsite']) ? $entry['anonwebsite'] : '',
      );
    }
  }
  $filter_tips = variable_get('guestbook_filter_tips', TRUE) ? _guestbook_form_filter_tips() : NULL;
  $form['message'] = array(
    '#type' => 'textarea',
    '#title' => t('Message'),
    '#cols' => 32,
    '#rows' => GUESTBOOK_TEXTAREA_ROWS,
    '#description' => $filter_tips,
    '#required' => TRUE,
    '#default_value' => !empty($entry['message']) ? $entry['message'] : '',
  );
  $form['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'] = _guestbook_access('post', $uid) == 'allowed' ? TRUE : FALSE;
  }
  if (variable_get('guestbook_form_location', 'above') == 'separate page') {
    $form['#redirect'] = !empty($_GET['destination']) ? $_GET['destination'] : 'guestbook/' . $uid;
  }
  $form['display'] = array(
    '#type' => 'value',
    '#value' => $display,
  );
  return $form;
}