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 7489287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:13:32+00:00 2026-05-29T15:13:32+00:00

I have setup some automatic form submission code. Basically when a form is submitted

  • 0

I have setup some automatic form submission code. Basically when a form is submitted javascript takes care of it, finding all inputs and such, and sending the data via ajax to the action attr of the form.

$j('body').delegate('form', 'submit', function(e) {
    e.preventDefault();
    if($j(this).prop('data-callback', true))
        asf.forms.processForm($j(this).attr('name'), $j(this).attr('data-callback'));
    else
        asf.forms.processForm($j(this).attr('name'));
});

But i need to include callbacks. I need to make the code global so i cant code any specifics for each form. So i thought of adding an attribute with the callback function name like so:

<form action="" method="" data-callback="posts.addPost()">

The problem is I dont know how to fire that function inside javascript. Any ideas?
I cant use onsubmit because i need access to all of the forms information which means doing this callback within the ajax response.

Thanks

  • 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-29T15:13:33+00:00Added an answer on May 29, 2026 at 3:13 pm

    To achieve this without resorting to eval, I suggest you store all your “form callbacks” in an object, like so:

    var formCallbacks = {
      'posts.addPost': function() {
        // ...
      },
      // ...
    };
    

    Using your data-callback mechanism, you would look up the callback in the response handler:

    function(args, callbackName) {
      formCallbacks[callbackName]();
      // ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some setup code in my functions.php file that sets permalinks and adds
I am trying to setup a few fixes in some code that have caught
I have an automatic replacement done by my vim setup, which systematically replaces all
I've created some MbUnit Test Fixtures that have SetUp methods marked with the SetUp
I have a setup function that runs onload to add some behaviours to elements.
I have a product setup executable that copies some files to the user's hard
My current setup : I have an entity object with some properties, among them
I have this following setup, a textarea named with some data in it that
I have some onchange events setup in jQuery which are used to populate a
I have some bindings that are setup as singletons. I want them to always

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.