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



You should write:
echo "window.location.href={$_SERVER['PHP_SELF']}";

But it won't work in your browser. Why do you want to put script tags
as action?

yangsuli@xxxxxxxxx napisał(a):
the code is like this
<form action="<?php dec_msgnum($cookie["usernum"]); echo "<script>";
echo "window.location.href=$_SERVER['PHP_SELF']"; echo '</script>';?>">
<input type="submit" value="忽略" /></form>

i also tried
<form action="<?php dec_msgnum($cookie["usernum"]);
header(default:$_SERVER['PHP_SELF'];';?>"> <input type="submit"
value="忽略" /></form>

it didnot work either :(

but this works perfectly well
<form action="<?php dec_msgnum($cookie["usernum"]); ';?>"> <input
type="submit" value="忽略" /></form>

do you think it is caused by some arguements missing?( may be it shoule
be $_SERVER['REQUEST_URI'] or $_SERVER['PHP_SELF']?xxxx=xxxxxx or
something)
Mateusz Markowski wrote:
Paste the code that you think may give parse error.

yangsuli@xxxxxxxxx napisal(a):
but why the second way didnot work out.......
i donot get where did the parse error come from :(
55555555555

Mateusz Markowski wrote:
Yes, I think so.

yangsuli@xxxxxxxxx napisal(a):
the problem is that i donnot want some script.php
i want to redirect the users back on the page they were just on,with
calling a function in advance :)
you think the flag thing is the best way to do it?

Mateusz Markowski wrote:
yangsuli@xxxxxxxxx napisal(a):
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?


PHP works on a server, not in your browser, so it can't just call
function when you click a link. You have to send a request to the
server which will cause your script to call this function. Your last
example is good way to do it. So you have such link:
script.php?call=helloworld

and in your file script.php such code:

if ($_GET['call'] == 'helloworld') {
echo 'Hello world!';
}

Then after clicking the link your browser sends a request, PHP decides
what to do, then server sends you a appropriate response.

.



Relevant Pages

  • Re: Choosing whitch button will act as submit button
    ... Use the script exactly as supplied for the browser. ... server-code cannot decide whitch button should be the submit button. ... one server side form tag, ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: how to call a function when somebody click a link?
    ... //we want user to go on this page and to add a flag which cause PHP to ... you donot think i shoud put the script tag? ... why the headerdidnot work either? ... data's been sent to client's browser. ...
    (comp.lang.php)
  • Re: different behavior - localserver vs prod server
    ... But I don't understand what you mean when you say to type the src urls ... into the browser to see if they are correct. ... > Smart Navigation and Client Range checking are implemented by client script, ... and how it behaves on the server. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Using anchor links within pages defined by GETS
    ... So the content in the browser ... sure the submitted value for pid is valid and not a NULL or SQL ... What URL is sent to the server? ... because your script should never see the ...
    (comp.lang.php)
  • Re: Is script type="text/perl" OK?
    ... :} I've asked this on a html forum but I'll ask it here also. ... Well, as long as your browser is able to execute the script, sure. ... Since the server is doing the running of the ...
    (comp.lang.perl.misc)