Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1007767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:40:04+00:00 2026-05-16T08:40:04+00:00

All I need to do is have a form that does this: User enters

  • 0

All I need to do is have a form that does this:

  1. User enters postcode in text box
  2. Upon submit user is redirected to mysite.com/[user postcode]

That’s it! I know validation etc. would be desirable as well, but I just need to get this working for now. I don’t mind if it’s harcoded or utilises the Drupal form API (actually I’d prefer the former!).

I know this is dead simple, but unfortunately I’m coming from a front-end background and have a bit to learn about this sort of thing 🙁

Cheers!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T08:40:05+00:00Added an answer on May 16, 2026 at 8:40 am

    This is pretty easy with the Form API and a custom module. You’ll build a form using the Form API and add a submit handler that changes the redirect for the form to whatever you’d like. Finally, you’ll need to create a way to access the form (either by creating a menu item or by creating a block).

    Here’s an example that implements a form like you want: you’ll want to peruse the Form API reference to see all the options you have when building a form. It also provides two ways to access the form:

    1. Using hook_menu() to provide a page for the form at http://example.com/test
    2. Using hook_block() to provide a block containing the form that you can add and move around on the block administration page.

    Example code:

    // Form builder. Form ID = function name
    function test_form($form_state) {
    
      $form['postcode'] = array(
        '#type' => 'textfield',
        '#title' => t('Postcode'),
        '#size' => 10,
        '#required' => TRUE,
      );
      $form['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Go'),
      );
    
      return $form;
    }
    
    // Form submit handler. Default handler is formid_submit()
    function test_form_submit($form, &$form_state) {
      // Redirect the user to http://example.com/test/<Postcode> upon submit
      $form_state['redirect'] = 'test/' . check_plain($form_state['values']['postcode']);
    }
    
    // Implementation of hook_menu(): used to create a page for the form
    function test_menu() {
    
      // Create a menu item for http://example.com/test that displays the form
      $items['test'] = array(
        'title' => 'Postcode form',
        'page callback' => 'drupal_get_form',
        'page arguments' => array('test_form'),
        'access arguments' => array('access content'),
        'type' => MENU_NORMAL_ITEM,
      );
    
      return $items;
    }
    
    // Implementation of hook_block(): used to create a movable block for the form
    function test_block($op = 'list', $delta = 0, $edit = array()) {
      switch ($op) {
        case 'list': // Show block info on Site Building -> Blocks
          $block['postcode']['info'] = t('Postcode form');
          break;
        case 'view':
          switch ($delta) {
            case 'postcode':
              $block['subject'] = t('Postcode');
              $block['content'] = drupal_get_form('test_form');
              break;
          }
          break;
      }
    
      return $block;
    }
    

    More info:

    • Creating modules – a tutorial: Drupal 6.x
    • Form API Quickstart Guide
    • Form API Reference
    • hook_menu() API reference
    • hook_block() API reference
    • Example of hook_block in Drupal 6
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page ( page 1 ) that accepts post requests, does some
Let me preface this question by stating that i don't usually condone the practice
I've been developing a piece of software that takes rules of the form 'A
My web-site has AJAX-powered search, that uses deep-linking. When user follows a link …
I'm trying to replace all dots found in a value entered by the user
I have a website, and offcourse like most websites it loads faster in Firefox.
I am currently writing a program which takes user input and creates rows of
I'm trying to follow Microsoft's example on how to add an All option to
I have been having a look to some post here related to the post
In my application I am using a timer to check for updates in an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.