how to call a function when somebody click a link?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

how to call a function when somebody click a link?

yangsuli@gmail.com

i want to creat a link
when somebody click the link
the php script calls a function,then display itself :)

i have tried
<a href=<? funtion(); echo=$_server['php_self'] ?>text</a>
but it will call the function whether i click the link

then i tried this (using forms)
<form action="<?php function(); echo "<script>"; echo
"window.location.href=$_SERVER['PHP_SELF']"; echo '</script>';?>">
<input type="submit" value="text" /></form>
but it didnot work either.
my browser said there were parse errors,T_STRING expected or
something....:(

now i am thinking using a flag,say,$functioncall,
 href=$_server[request_url]&functioncall=1
then if functioncall==1,call that function
but is it right?
is there some way simple to do that?

any suggestion is appreciated :)


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: how to call a function when somebody click a link?

Grant Cox

> any suggestion is appreciated :)


This is a Cake-PHP group, your questions show misunderstanding of basic
PHP and HTML.  I think you will get more help at another group, or from
working through some basic online tutorials.


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: how to call a function when somebody click a link?

bingo-2

hi Grant

you can use $html->link('title', 'url);
or $ajax->link('title', 'url', array('update'=>'div_name'));

Regards,
bingo


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: how to call a function when somebody click a link?

Apprentice-2
In reply to this post by yangsuli@gmail.com

Hi,

Obviously they won't work. You are mixing PHP, Javascript and HTML
improperly.

What you want to display when you click the link? Do you intend to use
Ajax?

Apprentice.

On Nov 4, 1:54 pm, "[hidden email]" <[hidden email]> wrote:

> i want to creat a link
> when somebody click the link
> the php script calls a function,then display itself :)
>
> i have tried
> <a href=<? funtion(); echo=$_server['php_self'] ?>text</a>
> but it will call the function whether i click the link
>
> then i tried this (using forms)
> <form action="<?php function(); echo "<script>"; echo
> "window.location.href=$_SERVER['PHP_SELF']"; echo '</script>';?>">
> <input type="submit" value="text" /></form>
> but it didnot work either.
> my browser said there were parse errors,T_STRING expected or
> something....:(
>
> now i am thinking using a flag,say,$functioncall,
>  href=$_server[request_url]&functioncall=1
> then if functioncall==1,call that function
> but is it right?
> is there some way simple to do that?
>
> any suggestion is appreciated :)


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: how to call a function when somebody click a link?

yangsuli@gmail.com

5555555555555555555

i want to redirect the user
back to the page they were just on,with calling a function in
advance....:(

maybe i should learn more about basic php?


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: how to call a function when somebody click a link?

Adrian Godong
Your second solution (the one setting up a flag) is the best way to do that. Don't forget to set any additional data you need in the session.

What you need to understand is like this: the client does not anything about your program. Period. It does not even know the original data (the one that resides in $this->blablabla). This is called stateless. Therefore, the server must maintain the data within the session variable for cross-page functions.

On 11/4/06, [hidden email] <[hidden email]> wrote:

5555555555555555555

i want to redirect the user
back to the page they were just on,with calling a function in
advance....:(

maybe i should learn more about basic php?





--
Adrian Godong
[hidden email]

Microsoft Student Ambassador
--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: how to call a function when somebody click a link?

yangsuli@gmail.com

thanks a lot........
i think the $_server{request] would contain the original data i need :)

but i don't understand why the form thing didnot work out......:(


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: how to call a function when somebody click a link?

yangsuli@gmail.com
In reply to this post by Adrian Godong
thanks & kissssssssssssssssssss :)
 
so you  think the form and javascript thing didnot work out because of arguements missing?

 
2006/11/4, Adrian Godong <[hidden email]>:
Your second solution (the one setting up a flag) is the best way to do that. Don't forget to set any additional data you need in the session.

What you need to understand is like this: the client does not anything about your program. Period. It does not even know the original data (the one that resides in $this->blablabla). This is called stateless. Therefore, the server must maintain the data within the session variable for cross-page functions.

On 11/4/06, [hidden email] <[hidden email]> wrote:

5555555555555555555

i want to redirect the user
back to the page they were just on,with calling a function in
advance....:(

maybe i should learn more about basic php?





--
Adrian Godong
[hidden email]

Microsoft Student Ambassador
--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

RE: how to call a function when somebody click a link?

Adrian Godong

Mm... Not quite right. To put it easily, here’s how:

 

First, read about MVC in the CakePHP manual. It gives a big picture about the whole web thing.

 

From what I understand, what you’re trying to do is to add a logic (code that processes objects and stuff) into your view (the THTML file). While possible, this is NOT a preferred way.

 

All of the logic (including any functions) need to be placed on the controller.

 

The controller will pass data to the view via $this->set(‘key’, ‘value’) method.

 

The view will never need to process anything but the values set from the above method.

 

The less the client (or the view) need to know about how to process data, the better your solution would be. Don’t hesitate to send back the data/tag/extra info to the server (using POST - <form> or GET - <a href>). That’s just the way the web works.

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of ??? Yang Su Li
Sent: 04 Nopember 2006 15:43
To: [hidden email]
Subject: Re: how to call a function when somebody click a link?

 

thanks & kissssssssssssssssssss :)

 

so you  think the form and javascript thing didnot work out because of arguements missing?

 

2006/11/4, Adrian Godong <[hidden email]>:

Your second solution (the one setting up a flag) is the best way to do that. Don't forget to set any additional data you need in the session.

What you need to understand is like this: the client does not anything about your program. Period. It does not even know the original data (the one that resides in $this->blablabla). This is called stateless. Therefore, the server must maintain the data within the session variable for cross-page functions.

On 11/4/06, [hidden email] <[hidden email]> wrote:


5555555555555555555

i want to redirect the user
back to the page they were just on,with calling a function in
advance....:(

maybe i should learn more about basic php?




--
Adrian Godong
[hidden email]

Microsoft Student Ambassador

<br


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: how to call a function when somebody click a link?

jc-17

It remains unclear to me why every1 makes this complicated.
You are clearly new to php but everyone's been there and we all got
help at the time.
Some explained how the web is stateless and this is very true but hard
to explain.
When you see a web page, it has been fetched from the server and it
displays html in your browser. When the page has finished loading, the
server does not care anymore, it's like a fly-by-night operation. The
page only exists, in that state, on your computer, in your temporary,
cached documents stored by your browser.
To change the state of the page, you can either go back to the server
ang get a new page (a request), or you can use client (browser) side
scripting (ecma) such as javascript to modify the page's value without
reloading the page, that is, without fetching a new page from the
server.
AJAX is merly javascript that fetches fresh DATA from the server
through an http request, and uses Javascript and DHTML to update the
cuurent page, without reloading it, with the new data. But it doesn't
sound like you'd want to do that just yet.
Looking at your need, here's a very simple example, you'll need 2
files:
Explanations: your php file can contain all your functions, where each
does different bits.
Active Server Pages (but not necessarily microsoft :) ) such as perl,
php, jsp etc take in parameters, also called name-value pairs.
the name value pairs create a query string for the request (to the web
server). The query string can be sent as POST or GET.
for example:
http://www.myserver.com/index.php?name=bob&email=bob@...
name value pair: name=bob
query string: name=bob&email=[hidden email]
so the format is name=value
name is the parameter name
value is the value assigned to that parameter
A query string is read by php and becomes accessible by php as
variables
For example, I could then access $name and $email in my php scripts
Anyhow you probably know that but just making it clear.
So:

file 1, say file1.htm
<form method="post" action="myPhpFunctions.php">
        <input type="hidden" name="action" value="doAndRedirect">
        <input type="submit" value="Do something in php and come back here">
</form>

and file 2, the myPhpFunctions.php file called by file1.htm:
<?
        // My functions that do things
        function someFunction1($someParameter='') {
                // do something
        }

        function someFunction2($someParameter='') {
                // do something
        }

        function someFunction3($someParameter='') {
                // do something
        }
        // etc...


        // my main program, where I decide what to do
        if ($action ==  "doSomething1") {
                someFunction1();
        } else if ($action ==  "doSomething2") {
                someFunction2();
        } else if ($action ==  "doSomething3") {
                someFunction3();
        } else if ($action == "doAndRedirect") {
                // note: "doAndRedirect" is what I put in the form's hidden action
field, so it will execute this
                // You could also just have in your html <a
href="myPhpFunctions.php?action=doAndRedirect">do something and come
back</a>
                someFunction3(); // call some function, remember that you variables
will be local once in the function so pass them or use the GLOBAL array
                // and
                header("Location:".$_SERVER["HTTP_REFERER"]); // redirect back to the
page that made the request, aka the referer; ie: to file1.htm
        }
?>


Hope this helps ;)
-J


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: how to call a function when somebody click a link?

yangsuli@gmail.com

thanks and kiss all
you guys help a lot....:)

i managed it by setting up a flag : msgignoreflag
when usr click the link,the href is linked to
$_server[request]&msgignoreflag
and the php script call the function only if the flag is set  :)


my code is like this
with msgignoreflag being the flag and the dec_msgnum the function i
would like to call
function print_body($nomsg = 0) {

        global $cookie;
        ?> <body bgproperties="fixed"> <?php
       // if(isset($_GET["msgignoreflag"]) {
          if($_GET["msgignoreflag"]==1) {
               dec_msgnum($cookie["usernum"]);
         }
        if( $msgnum = get_msgnum($cookie["usernum"]) && !$nomsg) {

                $msg = get_msg($cookie["id"], $msgnum);
                ?><table width=100% bgcolor=lightyellow>
                  <tr>
                  <td valign="top" nowrap="nowrap" width=25%><font
color="green"><?php echo $msg["id"]; ?></font> (<?php
                  echo ctime2($msg["time"]); ?>): </td>
                  <td align="left" valign="top" width=50%><?php echo
stripansi($msg["msg"]); ?></td>
                  <td align="right" valign="top" nowrap="nowrap"
width=15%>
                  <a href="<?php echo BBSCGI;
?>/bbssndmsg.php?reply=1&uid=<?php echo $msg["id"]; ?>">[回讯息]</a>
                  </td>
                  <td align="right" valign="top" nowrap="nowrap"
width=10%>
                  <a href="<?php echo $_SERVER['REQUEST_URI'];
?>&msgignoreflag=1">[忽略]</a>
                  </td>
                  </tr></table><?php
        }
}

thanks all you guys again
i appriciate your efforts to help me
kisssssssssss :)


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---