1

I have a php code written in index.php that contain a form with method post.

It also read from an external database and fill a table. To load this form I created a .module file with 2 functions _menu and _block, but I am not able to load the form (index.php) I need to load the form and to open it in the main content of the drupal page i used :

header("location
drupal_goto(
$external_link

but nothing is going right and it open in new blank page not in the main content like i want.

please it is urgent any help

closed as unclear what you're asking by kiamlaluno Jun 7 '16 at 8:45

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

4

The Drupal way

In Drupal we create similar form like this:

Create a custom module

  • Create a file sites/all/modules/own/form_test/form_test.info with this in it:

    name = form_test description = form_test core = 7.x package = Own

  • Create a file sites/all/modules/own/form_test/form_test.module

(start it with <?php tag, but don't add ending ?> tag)

Write these functions in your module:

function form_test_menu() {
  $items['formtest'] = array(
    'title' => 'Form Test',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('form_test_form'),
    'access callback' => TRUE,
    );
  return $items;
}

An explanation

form_test_menu creates a menu item in your navigation menu so we can have a place where to show our custom form. You can think that menu address referring to a page yoursite/formtest.

title

Title of the page.

page callback

Calls a function drupal_get_form which returns a render array for drupal_render().

page arguments

Here we pass our custom render array (which form_test_form returns) as an argument for drupal_get_form.

access callback

We define it TRUE so that everyone can access this page.

(Rendering means turning a structured array into HTML.)

function form_test_form($form,&$form_submit) {
  $form['firstname'] = array(
    '#title' => t('Firstname'),
    '#type' => 'textfield',
    '#required' => TRUE,
  );
  $form['lastname'] = array(
    '#title' => t('Lastname'),
    '#type' => 'textfield',
  );
  $form['submit'] = array(
    '#value' => 'Submit',
    '#type' => 'submit',
    );
  return $form;
}

An explanation

So we use render arrays to describe a form in drupal.

When you use a function to return a render array for drupal_get_form, there are two default parameters that are in use:

$form Holds the form array items we define inside the function when this function is called again.

&$form_submit This parameter holds various data items like the values you pass when you submit the form.

(Ampersand & means that this is a reference to a variable, so if we change this variable in this function, changes will show in the parent function too.)

Form items are added as arrays to the $form variable. Hash (#) sign refers to an attribute of the item.

Enable the module in admin/modules

Flush the caches

Form can be seen in yoursite/formtest, but it doesn't do anything yet.

OR more links are :

Drupal 7 - How to Make a Simple Module with a Form and Menu Link

Ten Step-by-Step Code Samples for Learning Form API

  • so i can not load my form i need to re-program the form using drupal function – hiba najjar Oct 8 '15 at 8:12
  • @hibanajjar Yes. Drupal implements pretty good form processing with advanced anti-tamper solutions and simply won't cooperate if you ignore them. You can make it, of course, but it's bad idea to try. You won't have your homemade solution as thoroughly tested as Drupal's one is. – Mołot Oct 8 '15 at 8:45

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