Basic Function question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
smoky989
Forum Commoner
Posts: 41
Joined: Mon Sep 02, 2002 1:14 pm

Basic Function question

Post by smoky989 »

I feel dumb asking this but how do you call a function from a form button. Acrually the button doesn't have to be in a form but I want to call a functio onclick. I can't find it in the book I have. Any help? Thanks in advance
User avatar
lazy_yogi
Forum Contributor
Posts: 243
Joined: Fri Jan 24, 2003 3:27 am

Post by lazy_yogi »

Put this into a file with .php extension and give it a go.
But this is executed server-side, I'm not sure if it can be executed in the clients browser like javasctipt is (I think javascript is executed client-side... not sure though .. only heard that).
Someone else might know

Hope it helps.

Code: Select all

<? 

       // The submit button is named 'send' below in 
       // the form and the form action calls the same
       // script by using    action=""
       // So if the form was called by pressing the
       // submit button, then  it recalls this page and
       // $send now exists (also $name holds what was
       // put in the textfield called name blow in the form)

if ($send) &#123;    // if submit buttin in form below was 
                // pressed, then   if($send)  .. is called
             printstuff($name);      // call function here
&#125;
else 
&#123;           // else print the form below

?>


<BR><BR><BR><FORM METHOD="POST" ACTION="">
<TABLE bgcolor = #f0f0f0 borderColor=gray cellPadding=3 border=2>
<TR><TD width = 80><CENTER>Username
         <TD width = 120><CENTER><INPUT TYPE="text" NAME="name" size="15">
<TR><TD colspan=2><CENTER>
<INPUT TYPE ="submit" NAME="send" VALUE="SetCookie">
</TABLE>
</FORM>


<?

&#125;   // this closes the else statement


function printstuff($in) &#123;
   print "name is $in";
&#125;


?>
Last edited by lazy_yogi on Sat Jan 25, 2003 12:40 am, edited 1 time in total.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

php runs serverside and has no connection to the "document" as soon as it is delivered to the client.
As long as actions stay clientside you have to use a clientside scripting language like javascript.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Post Reply