Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
#1 2008-06-23 02:49:48
- tomk
- Member
- Registered: 2008-05-15
- Posts: 12
...call a function from a button?
On an admin-side plug-in I’m making, which adds a new tab under Extensions, I want it to first when loaded just show a text, and a button.
When this button is pressed, reload the page with the same text, but also call a function that displays more information.
I didn’t catch the idea of the “zem_example_plugin.php” layout, could someone please clarify this for me?
Thanks in advance.
Offline
Re: ...call a function from a button?
Simple stuff, actually the only-TXP related stuff is how to register the tab, otherwise it’s basically up to your skills and what you can do :) First you just have to register the tab and add some privs to it:
if (@txpinterface == 'admin') {
add_privs('xxx_my_tab', '1,2');
register_tab("extensions", "xxx_my_tab", "xxx_my_tab");
register_callback("xxx_my_function_tab_to_call", "xxx_my_tab");
}
Here, we have made our tab that uses xxx_my_function_tab_to_call
-function as a base that holds everything that belongs to your admin tab. The tab is located somewhere in our TXP backend interface, in this time under tab called “Extensions”.
Our function could look something like this:
function xxx_my_function_tab_to_call() {
require_privs(''xxx_my_tab');
pagetop('hey, we got a title!');
# Here we can do anything - only the sky is limit.
}
As my comment line says, the sky is the only limit: there isn’t any limit (in theory). You could in example call that second function by using GETs or POSTs – or globals $event, $step (that are just those). In example, we could hook the second function inside xxx_my_function_tab_to_call
with simply this “GET-if aka ya’know the simple stuff”:
if(gps('did-i') == 'yes-you-did') xxx_our_second_function();
This comes true if we got ?did-i=yes-you-did
. Alternatively this can be transferred via post.
Offline
#3 2008-06-23 22:59:58
- tomk
- Member
- Registered: 2008-05-15
- Posts: 12
Re: ...call a function from a button?
Great thanks, it took me a while to understand how I assign in the fInput a value, but I did the following, which would put a button with label “Check”, and on press will assign the value “Check” to variable “action” on POST method.
fInput("submit", "action", "Check", "smallerbox")
How can I assign a different value for the variable then the text that appears in the button label?
Working fine by the way, but I still have this doubt.
Thanks in advance
Offline
Offline
#5 2008-06-24 16:54:14
- tomk
- Member
- Registered: 2008-05-15
- Posts: 12
Re: ...call a function from a button?
Great, thanks again.
One more question for the wise Gocom:
After pressing the button, it calls a function that works great but takes a while to finish processing (it checks URLs or the status codes, and then lists all of them).
I’m getting the following error:
Fatal error: Maximum execution time of 60 seconds exceeded ... \textpattern\lib\txplib_misc.php(574) : eval()'d code on line 322
where line 322 of txplib_misc.php is a part of the gps() function.
Is it so that there’s a limit for the response time of a GET or POST variable?
Can I avoid this?
Thanks!
EDIT:
Seems like that adding the following line works, but I’m not sure it’s the best way:
ini_set('max_execution_time', 3600);
What do you say?
Last edited by tomk (2008-06-24 17:22:31)
Offline
Re: ...call a function from a button?
tomk wrote:
Is it so that there’s a limit for the response time of a GET or POST variable?
Yes, there is processing timelimit, plus filesize and memory limit, if you haven’t yet noticed. The default is set to 60 seconds as your error says.
ini_set('max_execution_time', 3600);
May not be the best, as there could be some problems with it, but if it works, go for it. Best solution would be make your even script better :)
Offline
Pages: 1