RaythMistwalker Posted January 10, 2010 Share Posted January 10, 2010 <form action='<? function(); ?>'> I already know this doesn't actually work so does anyone know any way of calling a function that is on the SAME page using a form? Quote Link to comment https://forums.phpfreaks.com/topic/187984-php-function-from-form/ Share on other sites More sharing options...
Adam Posted January 10, 2010 Share Posted January 10, 2010 You mean as the form is submitted? .. <form onsubmit="myfunction();"> Quote Link to comment https://forums.phpfreaks.com/topic/187984-php-function-from-form/#findComment-992456 Share on other sites More sharing options...
Adam Posted January 10, 2010 Share Posted January 10, 2010 Sorry, didn't spot "PHP" in the title. No, strictly not. PHP isn't event driven like JS - although you could use AJAX to achieve this. Quote Link to comment https://forums.phpfreaks.com/topic/187984-php-function-from-form/#findComment-992458 Share on other sites More sharing options...
teamatomic Posted January 10, 2010 Share Posted January 10, 2010 $action = function(); <form action="<?=$action?>" HTH Teamtomic Quote Link to comment https://forums.phpfreaks.com/topic/187984-php-function-from-form/#findComment-992459 Share on other sites More sharing options...
oni-kun Posted January 11, 2010 Share Posted January 11, 2010 <form action='<? function(); ?>'> I already know this doesn't actually work so does anyone know any way of calling a function that is on the SAME page using a form? Nope. The action tag sends POST data, GET data, or calls a js event. AJAX will (easily) be required to send the POST/GET data to your PHP function, keeping it on the same page though. AJAX isn't too hard. Quote Link to comment https://forums.phpfreaks.com/topic/187984-php-function-from-form/#findComment-992488 Share on other sites More sharing options...
teamatomic Posted January 11, 2010 Share Posted January 11, 2010 [quote author=oni-kun link=topic=283612.msg1344773#msg1344773 Nope. The action tag sends POST data, GET data, or calls a js event. AJAX will (easily) be required to send the POST/GET data to your PHP function, keeping it on the same page though. AJAX isn't too hard. HUH? Nope. The method determines how the form data is sent. The action is merely a link extended to the submit. The submit triggers the browser to either append the data to the action-url or pass it in the body of the request(what is returned) as determined by the method as modified by the type. Once the request is processed the action is the "link" the browser uses to contact the server and submit the request body to. HTH Teamatomic Quote Link to comment https://forums.phpfreaks.com/topic/187984-php-function-from-form/#findComment-992511 Share on other sites More sharing options...
RaythMistwalker Posted January 11, 2010 Author Share Posted January 11, 2010 $action = function(); <form action="<?=$action?>" HTH Teamtomic This never worked it just started automatically running the function when i only need it to happen when the form is submitted. Quote Link to comment https://forums.phpfreaks.com/topic/187984-php-function-from-form/#findComment-992881 Share on other sites More sharing options...
wildteen88 Posted January 11, 2010 Share Posted January 11, 2010 If you want call a PHP function when the form is submitted. Then you'll need to do something like this <?php function some_function() { echo 'form submittted'; } if(isset($_POST['submit'])) { // call function here some_function(); } ?> <fom action="" method="post"> SOME FIELD HERE <input type="submit" name="submit" value="Submit" /> </form> Quote Link to comment https://forums.phpfreaks.com/topic/187984-php-function-from-form/#findComment-992939 Share on other sites More sharing options...
RaythMistwalker Posted January 11, 2010 Author Share Posted January 11, 2010 another small function question. I know they are formatted as: function name() { } or if i have a variable, function name($var) { } Say it has 2 variables am i correct in saying it is done like, function name($var1, $var2) { } and to call it would be name($var1, $var2); Also in the actual function declaration does it set the variables sent (say name(1, 2) then would $var1 = 1 and $var2 = 2? Quote Link to comment https://forums.phpfreaks.com/topic/187984-php-function-from-form/#findComment-992958 Share on other sites More sharing options...
wildteen88 Posted January 11, 2010 Share Posted January 11, 2010 Yes correct. For more information regarding functions please read this Quote Link to comment https://forums.phpfreaks.com/topic/187984-php-function-from-form/#findComment-992966 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.