This is pretty easy with the Form API and user module . You will create the form using the forms API and add a submit handler that will change the redirection for the form, whatever you want. Finally, you need to create a way to access the form (either by creating a menu item or by creating a block).
Here is an example that implements the form as you want: you will want to familiarize yourself with the link to the form API to view all the parameters that you have when creating the form. It also provides two ways to access the form:
- Using
hook_menu() to provide the form page http://example.com/test - Using
hook_block() , you will get a block containing a form that you can add and move on the block administration page.
Code example:
// 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; }
Additional Information:
user113292
source share