Sytax to call a function when Submit button is clicked

Links for php scripts

Moderators: macek, egami, gesf

vikaspa
New php-forum User
New php-forum User
Posts: 21
Joined: Wed Jun 19, 2002 10:03 pm

Sytax to call a function when Submit button is clicked

Postby vikaspa » Wed Aug 07, 2002 9:36 am

How to call a fuction whenever a submit button is lickd

I want to know rthe syntax..

Please help !!!

Vikaspa

DoppyNL

Postby DoppyNL » Wed Aug 07, 2002 9:50 am

PHP is a SERVER-SIDE language, so you cannot call a PHP-function when a button is clicked.

however, when you click the submit button, the form is submitted and the values in the form will be available in the script you are posting to, in there you can call the function you want.



also, I think this message is in the wrong forum, perhaps a moderator can move it to the correct forum.

Greetz Daan

shufty
New php-forum User
New php-forum User
Posts: 6
Joined: Sat Aug 17, 2002 5:45 am

Postby shufty » Sat Aug 17, 2002 1:58 pm

well if its in a form then request the function in the form action

Code: Select all

<form name="form2" action="function()" method="POST">


that should work

DoppyNL

Postby DoppyNL » Sat Aug 17, 2002 9:52 pm

shufty wrote:well if its in a form then request the function in the form action

Code: Select all

<form name="form2" action="function()" method="POST">


that should work

This is *not* a way to run an PHP-function. I'm not a javascript programmer, but I believe that this will call a javascript function.

Greetz Daan

doni

Postby doni » Thu Aug 29, 2002 12:44 am

do you mean a submit button in image form :?:

ok i'll try to write the code for you:
----------------------------------START PAGE-------------------------------------
<? if(go)
{ echo"Do the action";}
else
{ echo"OUT";}
?>


<HTML>
<BODY>
<input type="hidden" name="go' value="true">
<input type="image" src="GO.gif">

</BODY>
</HTML>

Jay

Re: Sytax to call a function when Submit button is clicked

Postby Jay » Thu Aug 29, 2002 2:39 am

vikaspa wrote:How to call a fuction whenever a submit button is lickd

I want to know rthe syntax..

Please help !!!

Vikaspa

You can't call a PHP function directly from a form, but you can call a javascript function (and use this javascript function to perhaps open a PHP page with the required variables etc).

You can do this in two ways: One is to insert the following in the <form> tag:
onSubmit=function();

The other is to change the submit button into:
<input type=button value='Submit This Form' onClick=function()>

Just remember to define your function as well!!

dan

My approximate solution.....

Postby dan » Thu Oct 31, 2002 4:48 am

I would be really gratefull for feedback on my 'session' function to call object functions automatically....

<?php

// Sesssion functions.

function session ( $get_vars = array(), $my_vars = array() )
{
if ( $get_vars["END_SESSION"] )
{
#echo "DESTROY<br>";
session_destroy();
}

if ( $get_vars["VIEW_PHP"] )
{
highlight_file( $_SERVER["SCRIPT_FILENAME"] );
exit;
}

foreach ( $my_vars as $name => $default )
{
$sess_name = "sess_". $name;
global $$sess_name;

if ( !session_is_registered( "$sess_name" ) )
{
#echo "BRAND NEW $sess_name<br>";
if ( is_array( $default ) )
{
#echo "OBJECT<br>";
$class = array_shift( $default );
$$sess_name = new $class( $default );
if ( method_exists ($$sess_name, "set_instance_name" ) )
{
$$sess_name->set_instance_name( $name ); // This allows the object to contruct URL's which call 'self' methods.
}
}
else{
#echo "VARIABLE $default<br>";
$$sess_name = $default;
}
}

if ( $new = $get_vars[$name] )
{
#echo "NEW $name<br>";
if ( is_array( $default ) )
{
#echo "OBJECT<br>";
$calls = explode( "*", $new );
foreach ( $calls as $call )
{
$call = explode( ":", $call );
$meth = array_shift( $call );

if ( method_exists( $$sess_name, $meth ) )
{
#echo "CALL $method<br>";
call_user_method_array( $meth, $$sess_name, $call );
}
else
{
echo "Bad Method:$meth<br>";
}
}
}
else
{
#echo "VARIABLE = $new";
$$sess_name = $new;
}
}
session_register("$sess_name");
}
}
?>


Return to “PHP Scripts”

Who is online

Users browsing this forum: No registered users and 3 guests

cron