English 中文(简体)
Drupal pass argument to page
原标题:

I have a custom Drupal module displaying some data in a table. Each row has a link which if clicked will delete the relevant row. Specifically, when the link is clicked it will take the user to a confirmation page. This page is really just a drupal form which says are you sure with two buttons: Yes , No . I figure I will need to pass the rowID to the confirmation page.

My question: What is the typically way to pass data to a new page in Drupal 7? I guess I could just add the rowID to the URL and use the $_GET[] from the confirmation page... I don t think this is very safe and was wondering if there was a better Drupal way.

Thanks!

最佳回答

You d use something like the following

<?php
function yourmod_menu() {
  // for examlple
  $items[ yourmod/foo/%/delete ] = array(
     title  =>  Delete a foo ,
     page callback  =>  drupal_get_form ,
     page arguments  => array( youmode_foo_delete_confirm , 2), // 2 is the position of foo_id
     access arguments  => array( delete foo rows ),
     type  => MENU_CALLBACK,
  );

  return $items;
}

function yourmod_foo_delete_confirm($form, &$form_state, $foo_id) {
  // load the row
  $foo = yourmod_get_foo($foo_id);

  // build your form, if you need to add anything to the confirm form
  // ....
  // Then use drupal s confirm form
  return confirm_form($form,
                  t( Are you sure you want to delete the foo %title? ,
                  array( %title  => $foo->title)),
                   path/to/redirect ,
                  t( Some description. ),
                  t( Delete ),
                  t( Cancel ));

}

?>

You can look here for examples of how core modules do it (have look at node_delete_confirm)

问题回答

The simplest solution would be to use an existing module created for this purpose:

You can configure which form values can be set from the URL, then rewrite the fields displayed in your table to generate the necessary links.

If the data are nodes, you can make the link node/%/delete where % is the nid. Drupal knows how to handle the delete page, as its a core path. Then, the delete confirmation follows the rest of the system and is very Drupal .

I am not sure if this changed at all in Drupal 7, but this is what I did for countless modules.





相关问题
Drupal Multi-language: Simple strings not translated

I m adding additional languages to a Drupal site that I m building. Getting the translation of content working is fairly easy using the Internationalisation module. Yet, simple things such as date ...

Setting up a WYSIWYG editor for Drupal site users [closed]

Looking through the Drupal contrib modules, and after a few Google searches, it becomes evident that there are any number of choices and combos available to set up a WYSIWYG editor in Drupal. I m ...

Change size of user/password login box

I don t know how to change the size of the login username/password boxes on the drupal site that I m trying to build. I m stumbling through the theming, and don t know where to find the file that ...

How does Drupal provide an edit/review/publish model?

How does Drupal support a means to update and review a website before it is published? Does it only allow you to preview a page at a time before you publish it or is there a way to create a site ...

Term for rotating header

I m looking for terminology that describes this behavior: The header of a web-page contains a different image every time you visit it. Update: It is not an advertisement, but images related to the ...

Has anyone checked out Drupal 7? [closed]

Has anyone checked out a copy of Drupal 7 yet? What do people think? I m pretty excited about the PDO and all of the designers I work with a very excited about the new admin interface/structure. Do ...

热门标签