Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7959985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:39:26+00:00 2026-06-04T04:39:26+00:00

I want to consolidate my PHP files into a common class file, but I

  • 0

I want to consolidate my PHP files into a common class file, but I am not sure how to call the function instead of the .php page. How can I call sendEmail() in the form section of my HTML page?


HMTL
<form action="form_class.php" id="frmAirport" method="post">
Full Name: <span style="white-space: pre;"> 
</span><input name="name" type="text" /><br /><br />
Email Address: <input name="email" type="text" /><br /><br />
Subject: <span style="white-space: pre;">       
</span><input name="subject" type="text" /><br /><br />
<textarea id="txtComments" cols="30" rows="10">Comments</textarea><br />
<input type="submit" value="Send" />
</form>

<?php
function addPerson() {
//do stuff here 
}

function sendEmail() {
//do some stuff here 

}
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T04:39:27+00:00Added an answer on June 4, 2026 at 4:39 am

    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 
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several ajax call on my page and I want to consolidate them
Want the function to sort the table by HP but if duplicate HPs then
want to rewrite urls like site.com/software to wp-content/themes/dir/software.php and something is not working.. Here's
I have a situation where I'm trying to consolidate several Javascript files into one,
I want to consolidate values in my table using SELECT Query. My table has
want to open pdf file when a user clicks on hyperlink shown in gridview
Want to run javascript function from parent window in child window Example I have
i want a macro to consolidate the data form multiple sheets to one sheet..
I've done a lot of research but no luck... I want to have a
I have multiple lists of strings, IList<string> , that I want to consolidate in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.