You can't call PHP functions directly. However, if the php file is formatted how you displayed here with only two functions you could pass a flag in as a POST field and have a logic block determine which function call based on that flag. It's not ideal but it would work for your purposes. However, this would force the page to refresh and you would probably have to load a different page after the function returns so you may want to simply implement this as an ajax call to avoid the page refresh.
Edit based on your comment (Using jQuery Ajax):
I am using the .ajax() jQuery function. My intentions create one php file that contains multiple functions for different html forms. – tmhenson
Well in this case, you can have your file contain the logic block to "route" the request to the right function and finally return the result.
I'll try to provide an option for what you want to do based on some simple jQuery. Say you have something like this:
Java Script:
$("#button1").click(function(e){
e.preventDefault(); // prevents submit event if button is a submit
ajax_route('ap');
});
$("#button2").click(function(e){
e.preventDefault(); // prevents submit event if button is a submit
ajax_route('se');
});
function ajax_route(action_requested){
$.post("ajax_handler.php", {action : action_requested}, function(data){
if (data.length>0){
alert("Hoorah! Completed the action requested: "+action_requested);
}
})
}
PHP (inside ajax_handler.php)
<?php
// make sure u have an action to take
if(isset($_POST['action'])
switch($_POST['action']){
case 'ap': addPerson(); break;
case 'se': sendEmail(); break;
default: break;
}
}
function addPerson() {
//do stuff here
}
function sendEmail() {
//do some stuff here
}
?>