Sytax to call a function when Submit button is clicked

A

Anonymous

Guest
How to call a fuction whenever a submit button is lickd

I want to know rthe syntax..

Please help !!!

Vikaspa
 
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
 
well if its in a form then request the function in the form action
Code:
<form name="form2" action="function()" method="POST">

that should work
 
shufty said:
well if its in a form then request the function in the form action
Code:
<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
 
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>
 
vikaspa said:
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!!
 
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");
}
}
?>
 
Back
Top