2

I am very new to drupal and working with D7

I have created two form with a custom module. mysite.com/custom is showing both the forms at the same time

I want each of the form to be shown with 2 different URLs. eg mysite.com/custom1 eg mysite.com/custom2

How is it possible.OR is it not possible at all. am i totally wrong in understanding how the module and forms work?

code

function custom_menu() {
  $items['custom'] = array(
      'title' => t('Custom'),
      //'page callback' => 'drupal_get_form',
      'page callback' => 'custom_page_callback',
      //'page arguments' => array('custom_form'),
      //'access arguments' => array('custom module'),
      'access callback' => TRUE,
  );

  return $items;
}

function custom_page_callback() {
  $build = array();

  // Render your two forms here.
  $build['form_one'] = drupal_get_form('custom_form');
  $build['form_two'] = drupal_get_form('custom_second_form');

  return $build;
}
/**
 * Our custom form.
 */
function custom_form($form, &$form_submit) {
  $form['title'] = array(
      '#title' => t('Give a title'),
      '#type' => 'textfield',
      '#required' => TRUE,
  );
  $form['name'] = array(
      '#name' => t('Give a Name'),
      '#type' => 'textfield',
      '#required' => FALSE,
      '#maxlength' => 25,
      '#size' => 10,
  );
  $form['submit'] = array(
      '#value' => 'Add',
      '#type' => 'submit',
  );
  return $form;
}
/**
 * Our custom form second.
 */
function custom_second_form($form, &$form_submit) {
  $form['title'] = array(
      '#title' => t('Give a title'),
      '#type' => 'textfield',
      '#required' => TRUE,
  );

  $form['submit'] = array(
      '#value' => 'Add',
      '#type' => 'submit',
  );
  return $form;
}

Thanks all

1
  • Please post your code in question, so we can answer your question Commented Nov 30, 2012 at 9:03

2 Answers 2

3

Have to make small change on function custom_menu.

Try this code.

function custom_menu() {
  $items['custom/first'] = array(
      'title' => t('Custom'),
      //'page callback' => 'drupal_get_form',
      'page callback' => 'custom_page_first',
      //'page arguments' => array('custom_form'),
      //'access arguments' => array('custom module'),
      'access callback' => TRUE,
  );
  $items['custom/second'] = array(
      'title' => t('Custom'),
      //'page callback' => 'drupal_get_form',
      'page callback' => 'custom_page_second',
      //'page arguments' => array('custom_form'),
      //'access arguments' => array('custom module'),
      'access callback' => TRUE,
  );

  return $items;
}
0
3

If you want to show two forms in two different pages, just define two menu items.

function custom_menu() {
  $items['custom'] = array(
    'title' => 'Custom form #1',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('custom_form'),
    'access callback' => TRUE,
  );

  $items['other_custom'] = array(
    'title' => 'Custom form #2',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('custom_second_form'),
    'access callback' => TRUE,
  );

  return $items;
}

As side note, the content of the "title" and "description" are not passed to t(), as I did.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.