a problem

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

a problem

yangsuli@gmail.com

hello everyone:)
i want to create a link
when somebody click the link
the php calls an function and then display itself again:)

i have tried
<a href="<? php function_i_want(); echo $_SERVER['PHP_SELF']
?>">text</a>
but it will call the function_i_want whether i click the link.

then i tried to solve this problem by using html forms
the code is like this:
<form action="<?php funcion_i_want();echo "<script>; echo
window.location.href=$_SERVER['PHP_SELF']; echo"</seript>; ?>">
<input type="submit",value=sometext /></form>
it didnot work either....:(
my browser shows some parse error,T_SRING expected or something like
that.....

is there any simple way to do this?
nwo i am thinking use a flag,say functioncalled,
set functioncalled=1 if the link is clicked
then call function_i_want when functioncalled==1
but i think it is too complex......:(

thanks a lot :)


--~--~---------~--~----~------------~-------~--~----~
 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: a problem

andrew-128
You can't call the function from <a href. For this, u have to submit the form on the same page

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

hello everyone:)
i want to create a link
when somebody click the link
the php calls an function and then display itself again:)

i have tried
<a href="<? php function_i_want(); echo $_SERVER['PHP_SELF']
?>">text</a>
but it will call the function_i_want whether i click the link.

then i tried to solve this problem by using html forms
the code is like this:
<form action="<?php funcion_i_want();echo "<script>; echo
window.location.href=$_SERVER['PHP_SELF']; echo"</seript>; ?>">
<input type="submit",value=sometext /></form>
it didnot work either....:(
my browser shows some parse error,T_SRING expected or something like
that.....

is there any simple way to do this?
nwo i am thinking use a flag,say functioncalled,
set functioncalled=1 if the link is clicked
then call function_i_want when functioncalled==1
but i think it is too complex......:(

thanks a lot :)





--
Thanks,
Kushal
--~--~---------~--~----~------------~-------~--~----~
 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: a problem

yangsuli@gmail.com

well
actually,i want to call the function only when the link is
clicked......
is there anyway to do this without forms?


--~--~---------~--~----~------------~-------~--~----~
 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: a problem

Grant Cox

PHP is a server side language, not client.  You will need to have the
link requesting a cake action (this can be done with ajax if you don't
want the page to refresh).  The cake action should redirect the user
back to the page they were just on.


On Nov 4, 3:58 pm, "[hidden email]" <[hidden email]> wrote:
> well
> actually,i want to call the function only when the link is
> clicked......
> is there anyway to do this without forms?


--~--~---------~--~----~------------~-------~--~----~
 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: a problem

yangsuli@gmail.com

i have tried to do this by using forms
action="<? php function(); header(location:$_server[request_url] ?>
but it didnot work out.....:(
parse error or something........

what is cake action?
would you please explain it :)


--~--~---------~--~----~------------~-------~--~----~
 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: a problem

Apprentice-2

There is nothing wrong with Cake... I can't see that your PHP code is
correct.

You can use Ajax to submit info to the PHP script when a user clicks on
the link and then get the result from the script's response.

If you want us to help please state clearly & in-detail your intention
or attach the HTML & PHP file.

Viet.

On Nov 4, 2:39 pm, "[hidden email]" <[hidden email]> wrote:
> i have tried to do this by using forms
> action="<? php function(); header(location:$_server[request_url] ?>
> but it didnot work out.....:(
> parse error or something........
>
> what is cake action?
> would you please explain it :)


--~--~---------~--~----~------------~-------~--~----~
 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: a problem

fr33dom

morning yangsuli,

as these guys have mentioned, you're going to have to submit your page
and have the PHP run it's function before displaying the same page
again.

i.e.

1. user clicks a link
<a href="<?php echo $this->params['url']['url']; ?>/argument"
title="click me">click here to perform function</a>

2. this sends the request to Cake at the server end where you can
process it in your controller. let's pretend your controller is users
and your action is view.

in your users_controllers.php file you would have this action:

function view($argument = null) {

    if (!is_null($argument)) {

        // perform your function
    }

    // do the rest of the processing required for this function

}

Does this make sense?

cheers,
mikee

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

>
> There is nothing wrong with Cake... I can't see that your PHP code is
> correct.
>
> You can use Ajax to submit info to the PHP script when a user clicks on
> the link and then get the result from the script's response.
>
> If you want us to help please state clearly & in-detail your intention
> or attach the HTML & PHP file.
>
> Viet.
>
> On Nov 4, 2:39 pm, "[hidden email]" <[hidden email]> wrote:
> > i have tried to do this by using forms
> > action="<? php function(); header(location:$_server[request_url] ?>
> > but it didnot work out.....:(
> > parse error or something........
> >
> > what is cake action?
> > would you please explain it :)
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
 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: a problem

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
-~----------~----~----~----~------~----~------~--~---