Hmm.

Hey, Mathieu. Many thanks for the reply. However, I currently AM using a
form. What I'm trying to get away from, is the two step process:

1.  pick your option
2.  click submit

I'm trying to get a one-step process, where the user can click on a link,
and that calls the function.

JavaScript won't work, because it's client side, and can't be used to call
a server-side php function (unless you tell me some neat trick I don't
know about yet). See my struggle now?




On Fri, 26 Jul 2002, Mathieu Dumoulin wrote:

> Date: Fri, 26 Jul 2002 21:46:00 -0400
> From: Mathieu Dumoulin <[EMAIL PROTECTED]>
> To: [EMAIL PROTECTED]
> Subject: Re: [PHP] calling user-defined php functions from <a href> tag
>
> Easy
>
> Your form when pressed the button submit will send the data from the form
> via post (Which is the best method) to the functions.php with all the
> functions. What you need to modify now is that all the <input type=radio>
> need to be modified to "FuncToExec" name.
>
> When you receive the input of the form, you just verify what $FuncToExec is
> and execute the correct function.
>
> <?php
>
> if($FuncToExec == "joe"){
>     joe();
> }elseif(...){
> }
>
> ... (All functions in your file goes there)...
>
> ?>
>
> Now what you also want to add is that if your JOE function is to return
> something, the IF ELSE calling that thing should intercept the value
> returned and this part of the script should either do something with that
> value or just redirect the value to another script by GET mode:
>
> header("location: myresultpage.php?result=$result");
>
> There, sorted that out right?
>
> have fun
> insanecoder!
>
> "Michael" <[EMAIL PROTECTED]> wrote in message
> [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> >
> >
> > Hi, Justin.
> >
> > Thanks very much for the reponse.
> > Yeah, this is a SUPER simplified form of my question, so please don't
> > expect it to make sense. Heh.
> >
> > Basically, I have a php file with dozens of functions in it. I want ONE of
> > them to get called when a link is clicked.
> >
> > Currently, I achieve this with the use of HTML forms. My form generates a
> > list of options. And the user has to select an option, then click the
> > SUBMIT button.
> >
> > But I want to make it a one-step process, whereby the user only needs to
> > click on the option.
> >
> > Of course, you can't achieve this in a form with JavaScript, but the
> > JavaScript code won't let me execute a server-side php function
> > (obviously).
> >
> > And I don't want to just shoot the link off to another page (even though
> > that's what it was designed to do). I want to call a very specific
> > function.
> >
> > Tricky, I know.   :(
> >
> > -- Michael
> >
> > On Sat, 27 Jul 2002, Justin French wrote:
> >
> > > Date: Sat, 27 Jul 2002 11:35:23 +1000
> > > From: Justin French <[EMAIL PROTECTED]>
> > > To: Michael <[EMAIL PROTECTED]>, [EMAIL PROTECTED]
> > > Subject: Re: [PHP] calling user-defined php functions from <a href> tag
> > >
> > > on 27/07/02 12:09 PM, Michael ([EMAIL PROTECTED]) wrote:
> > >
> > > > <?php
> > > > function joe() {
> > > > $temp1=10;
> > > > $temp2=20;
> > > > $result=$temp1+$temp2;
> > > > echo "The result of this function is: " . $result;
> > > > }
> > > > ?>
> > >
> > > wouldn't that be
> > >
> > > return "The result of this function is: " . $result;
> > >
> > > rather than echo?
> > >
> > >
> > > Anyhoo, you haven't specified HOW you want to communicate the result of
> the
> > > function to the browser.
> > >
> > > A HREF is supposed to take you off to another page (amongst other
> things),
> > > which might be what you're after.
> > >
> > > JavaScript (*shudder*) is designed to provide client-side actions, so
> maybe
> > > a javascript alert is what you want, or a pop-up window, or who knows
> what.
> > >
> > > You need to decide what happens, in a story board fashion.
> > >
> > >
> > > Remember, everything in PHP code takes place on the server, BEFORE the
> > > browser gets it.
> > >
> > >
> > > Example of using JS alert:
> > >
> > > <HTML>
> > > <?
> > > function joe() {
> > >     $temp1=10;
> > >     $temp2=20;
> > >     $result=$temp1+$temp2;
> > >     return "The result of this function is: " . $result;
> > > }
> > > ?>
> > > <A HREF="#" onclick="javascript:alert('<?=joe()?>')">calculate foo</a>
> > > </HTML>
> > >
> > > but really, I can't understand why you wouldn't just do:
> > >
> > > <HTML>
> > > <?
> > > $result=$temp1+$temp2;
> > > echo "Total: {$result}";
> > > ?>
> > > </HTML>
> > >
> > > Why do they have to click?
> > >
> > >
> > > You'll have to check all the javascript stuff and maybe massage it,
> because
> > > I haven't tested this, and haven't written much JS in the past coupla
> years.
> > >
> > >
> > > Beware of the limitations of relying on javascript for anything though
> :)
> > >
> > >
> > > Justin French
> > >
> > >
> > > --
> > > PHP General Mailing List (http://www.php.net/)
> > > To unsubscribe, visit: http://www.php.net/unsub.php
> > >
> > >
> >
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to