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

  • SEARCH
  • Home
  • 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 4096896
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:06:16+00:00 2026-05-20T20:06:16+00:00

I have following function. I want to call this function when user click on

  • 0

I have following function. I want to call this function when user click on Hyperlink (unactivate my account). what is the best way to call function on href click? thanks

function deleteUserMeta($userID) {
    delete_usermeta($userID, 'subscription_id');
    delete_usermeta($userID, 'ref_id');
    delete_usermeta($userID, 'users_name');
    delete_usermeta($userID, 'trans_key');
}
  • 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-05-20T20:06:17+00:00Added an answer on May 20, 2026 at 8:06 pm

    As Thorben mentioned, you can’t execute PHP functions on browser events, since the language is server-side and not client-side. However, there are a couple of ways to address this:

    1. SERVER-SIDE (PHP)

    You can’t call a PHP function on a browser event (link click, for example), but you can call it first thing on the page that’s loaded when you click though the hyperlink — let’s call it ‘next.php’. To do this, call your function deleteUserMeta() conditionally, at the very top of ‘next.php’. The catch is you’ll need to pass some variables to this page so that you can check the condition, and execute the function. Use GET to pass a variable through the hyperlink like this:

    <a href="next.php?unsubscribe=true&userID=343">Unsubscribe</a>
    

    How you want to pass the userId is up to you. In the above example it’s hard-coded, but you might also somehow set it with PHP like so:

    <a href="next.php?unsubscribe=true&userID=<?php echo $userID;?>">Unsubscribe</a>
    

    Now on ‘next.php’, use a condition to assess that variable:

    <?php
    if($_REQUEST['unsubscribe'] == 'true'){
        deleteUserMeta($_REQUEST['userID']);
    }
    ?>
    

    2. CLIENT-SIDE (AJAX)

    The other way to perform this operation is to do it client-side with some AJAX. If you’re not familiar with Javascript/jQuery/AJAX I would probably stick to the other solution, as it’s probably easier to implement. If you’re using jQuery already though, this shouldn’t be too hard. With jQuery, you can bind this function to the actual click event of your hyperlink. This way, this entire operation can happen without refreshing the page:

    <a href="#" onclick="ajaxDeleteUserMeta()">Unsubscribe/a>
    

    Now you’ll need two things:
    1. The same PHP file “next.php” that was required for the first solution just contains a call to your function, deleteUserMeta($userId)
    2. A javascript function called ajaxDeleteUserMeta(), so create one in your JS like this: (since this is a named function, it doesn’t need to go inside jQuery(document).ready(function(){}); like most anonymous jQuery functions do.)

    function ajaxDeleteUserMeta(){
    
    var userID = ''; // fill this in to somehow acquire the userID client-side...
    
    jQuery.ajax({
       type: "POST",
       url: "next.php", /* this will make an ajax request to next.php, which contains the call to your original delete function. Essentially, this ajax call will hit your original server-side function from the client-side.*/
       data: "userID="+userID+"&unsubscribe=true", /*here you can pass a POST variable to next.php that will be interpreted by the conditional function.*/
       success: function(msg){
         alert( "Data Saved: User ID " + userID + " deleted." );
       }
    
    });
    
    }
    

    Long-winded, but I hope some of that makes a little sense.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following function: CREATE FUNCTION fGetTransactionStatusLog ( @TransactionID int ) RETURNS varchar(8000)
I have the following function that is pulling data from a database. The ajax
So: I have the following function, adapted from a formula found online, which takes
Let's say I have the following function: sumAll :: [(Int,Int)] -> Int sumAll xs
I have the following Oracle function: function get_job_no return number is V_job_no number; begin
Say I have the following code: function One() {} One.prototype.x = undefined; function Two()
I have the following intentionally trivial function: void ReplaceSome(ref string text) { StringBuilder sb
I have the following serialization method: Private Function SerializeData(ByVal data As cData) As String
I have the following situation: I have a certain function that runs a loop
I have a stored procedure with the following header: FUNCTION SaveShipment (p_user_id IN INTEGER,

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.