You are here

function _blocks404_form_alter in 404 Blocks 5

Implements hook_form_alter().

We need this to be able to submit any forms from the error pages, otherwise the form POSTs to the error page and the form is not processed.

1 call to _blocks404_form_alter()
blocks404_form_alter in ./blocks404.module
Implements hook_form_alter().

File

./blocks404.active.inc, line 88

Code

function _blocks404_form_alter($form_id, &$form) {
  if ($_GET['q'] == BLOCKS404_PAGE) {

    // Form actions that POST to the 404 page won't work properly.
    if ($form['#action'] == url(BLOCKS404_PAGE) || $form['#action'] == url(BLOCKS404_ORIGINAL_QUERY) || $form_id == 'user_login_block' || $form['#action'] == url(BLOCKS404_PAGE, array(
      'query' => 'destination=' . BLOCKS404_ORIGINAL_QUERY,
    ))) {
      $form['#action'] = url('<front>');
    }
    elseif (strpos($form['#action'], 'destination=' . urlencode(BLOCKS404_ORIGINAL_QUERY)) !== FALSE) {

      // Deconstruct the URL.
      list(, $path) = explode($GLOBALS['base_path'], $form['#action']);
      list($path, $query) = explode('?', $path);
      $query = explode('&', $query);
      if (($pos = array_search('destination=' . urlencode(BLOCKS404_ORIGINAL_QUERY), $query)) !== FALSE) {

        // Remove the broken redirection.
        unset($query[$pos]);

        // Reconstruct the URL.
        $form['#action'] = url($path, array(
          'query' => $query,
        ));
      }
    }
  }
}