Jump to content

Calling a function from within a template (like VB)?


jeffery1493

Recommended Posts

Hi All,

I have a PHP template that is constructed (greatly simplified) like this:

$template-> assign_vars(array(
                      'L_HEADER_MESSAGE'  =>  $lang['header_message'],      // "Click here to execute function!"
                      . . .
                      'ACTION'                   =>  perform_the_action(),
                      . . .
                                 )
                      );

$template-> pparse ('body');



In the template, there is an icon which you click to execute.    In the place of perform_the_action(), there used to be a web address, like http://www.paypal.com.   This used to work fine, when you clicked the icon, you would then go to the paypal address.

Instead however, I want to call the function: perform_the_action when the icon is clicked.
The problem is, when PHP runs, it plows right through and immediately executes perform_the_action(), whether you click it or not.



Is there some way to have a button in a template in PHP, so when you click it you execute a function in your program, but the function won't execute UNTIL you click it?   I figure I'd save twelve hours of web hunting by asking.........

Thanks for any advice,

JEFFERY1493.

Link to comment
Share on other sites

I don't understand why PHP can't do simple things like this.  Its almost like to program on PHP you have to first learn about 8 other languages (JavaScript, Ajax, MySql, Html, Curl......)    :'(
I understand it isn't an 'object oriented' language, but sheesh, I'm not painting the Sistine Chapel here.
A PHP freak, I may not become..........

Link to comment
Share on other sites

OR, PHP stands for PHP: Hypertext Preprocessor.
PRE- meaning BEFORE. Meaning it's designed to handle scripting on html pages before they out processed by the browser. It originally mean Personal Home Pages. It's not meant to imitate a desktop application, in which you could press a button and have a function run. In PHP, in order to run new code, you have to load a new page. This is basic stuff. AJAX and CURL help provide ways to imitate a desktop app, like what you want.

Complaining about having to know about html is like complaining about having to know how to use a pencil when you just want to write a little note! PHP is designed to be used IN html pages and with databases. You don't have to use MySQL with PHP, but it makes it faster and easier than using flatfiles for everything you want to persist. Other languages interact with files and dbs as well, it's called "Persistent Storage".

ANYWAY, AJAX is NOT hard. The mootools framework uses one freaking line of JS in order to do what you want. Chillax.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.