-1

I have written a custom module which creates a link on the page.

When you clicking the link

<a href="path_to_module/lib/script.php?lotOfparameters=value>
  Do it
</a>

a php file is called, where all the logic of the module is done (create a node with predefined field values, create a pane for panels module and other stuff).

But i think this isn´t the recommend way to to this in Drupal. Doing this in the .php file is tooking sometimes a lot of time, so a progress bar would be nice for exmaple.

So I am looking for the best way to do logic when a button is clicked on the site.

EDIT: I think that was a bad description for my problem, so i try to make this better.

In my Templates, e.g. page.tpl.php and node.tpl.php, I´m printing a link to create a button. If the buttons gets clicked I want to do some stuff, i think what exactly is irrelevant. But I'm doing this with a direct link to a .php file in the link. In this .php file all things are executed. And I think THIS isnt the best way to do things in drupal.

2
  • While this link (drupal.org/node/102338) is for Drupal 6, it gives a great overview of Drupal's menu system and callbacks and so forth that detail how (IMHO) you should set up logic for when a button/link is clicked on your site.
    – Jimajamma
    Commented Dec 15, 2013 at 19:12
  • There's so many problems with the approach to solution here, that it's hard to know where to begin. Scrap everything, and start reading from the link Jimajamma gave you.
    – Letharion
    Commented Dec 16, 2013 at 20:20

2 Answers 2

3

Extremely broad question, so an extremely broad answer...

Use the Batch API.

If you need more code examples than the docs page provides, the examples module has a lot of good, related code.

0

What @Clive said -- that's the best way to execute a long process in manageable chunks -- but if you also want to kick this off in the background without reloading the page, you'll want to use the Ajax framework to execute it.

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