Title: Execute Function on Form Submission
Last modified: November 16, 2016

---

# Execute Function on Form Submission

 *  Resolved [Nugerama](https://wordpress.org/support/users/nugerama/)
 * (@nugerama)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/execute-function-on-form-submission/)
 * I’m looking for a solution to add a number of points (using MyCred plugin) to
   a user’s profile when they submit a form. More specifically, I’m hoping to use
   Toro Forms to create surveys for users to fill out and issue the points as a 
   reward for submitting a response.
 * How might I hook into that form action to execute the mycred_add() function, 
   passing the user’s ID and thus crediting their account?

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Thread Starter [Nugerama](https://wordpress.org/support/users/nugerama/)
 * (@nugerama)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/execute-function-on-form-submission/#post-8445609)
 * Okay, I’m now using the Form Action API code snippet (here: [https://torro-forms.com/api/extending/form-actions/](https://torro-forms.com/api/extending/form-actions/))
   which extends the Torro_Form_Action class. I’m a little out of my depth here,
   can anyone explain why I get:
 * Fatal error: Call to protected Torro_Form_Action::__construct() from context ‘
   Torro_Manager’ in /Applications/MAMP/htdocs/sandbox/wp-content/plugins/torro-
   forms/core/managers/class-manager.php on line 66
 *  Plugin Author [Sven Wagener](https://wordpress.org/support/users/mahype/)
 * (@mahype)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/execute-function-on-form-submission/#post-8452874)
 * Hi,
 * if you want to use MyCred, the eaysiest way to do that is to use the shortcodes
   of MyCred.
 * Just put somethong like
 * [mycred_give amount=”10″ log=”He answered the Form” ref=”bonus_points”]
 * to Redirections > Textmessage in the form. I think thats the easiest way to implement
   it. We don’t have an extra plugin for that yet. But we are thinking about to 
   create an extension for that.
 * I will check the error and have already added an issue for that on Github:
    [https://github.com/awsmug/torro-forms/issues/330](https://github.com/awsmug/torro-forms/issues/330)
 * This problem will be solved the next days in the develope version and will come
   with 1.0.0 beta 8.
 * Thank you for reporting! 🙂
 * Greetings,
 * Sven
 *  Thread Starter [Nugerama](https://wordpress.org/support/users/nugerama/)
 * (@nugerama)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/execute-function-on-form-submission/#post-8457666)
 * Thanks for your response, Sven. On further investigation of the working form 
   actions inside the plugin I found that I could get mine working by including 
   a couple of extra functions, namely:
 * `private static $instance = null;`
 * and
 *     ```
       public static function instance() {
       	if ( null === self::$instance ) {
       		self::$instance = new self();
       	}
       	return self::$instance;
       }
       ```
   
 * With the hooked action in place I’ve managed to add a tab in the admin which 
   let’s the user allocate points to a form and then runs the `mycred_add` function
   on submission. I spotted a couple of other typos in the example in your docs 
   too: a missing semi-colon on line 33 and the last line tries to register the 
   main class instead of the new one, `torro()->actions()->register( 'Torro_Form_Action');`
   should be `torro()->actions()->register( 'My_Action' );`.
 * Great plugin. This has so far proved the perfect solution to my client’s requirement
   for a survey builder.
 * Thanks again
 *  Plugin Author [Sven Wagener](https://wordpress.org/support/users/mahype/)
 * (@mahype)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/execute-function-on-form-submission/#post-8462833)
 * That makes me happy! 🙂
 * And thank you for your investigation. I will check and fix this today.
 * If you want to support us, I would be very grateful if you would rate the plugin!
 * Greetings,
 * Sven
 *  Thread Starter [Nugerama](https://wordpress.org/support/users/nugerama/)
 * (@nugerama)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/execute-function-on-form-submission/#post-8462893)
 * Of course, done.
 *  Plugin Author [Sven Wagener](https://wordpress.org/support/users/mahype/)
 * (@mahype)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/execute-function-on-form-submission/#post-8472056)
 * Hi,
 * I have fixed the problem, so that you do not need your $instance variable and
   function anymore. The cunstructor had to be public. I have changed this for the
   upcoming version 1.0.0 beta 8.
 * [https://github.com/awsmug/torro-forms/issues/330](https://github.com/awsmug/torro-forms/issues/330)
 * You can get it, if you download the develop version from Github.
 * [https://github.com/awsmug/torro-forms/tree/develop](https://github.com/awsmug/torro-forms/tree/develop)
 * Also I have fixed my errors in the documentation.
 * Greetings,
 * Sven
    -  This reply was modified 9 years, 6 months ago by [Sven Wagener](https://wordpress.org/support/users/mahype/).

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Execute Function on Form Submission’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/torro-forms_a76868.svg)
 * [Torro Forms](https://wordpress.org/plugins/torro-forms/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/torro-forms/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/torro-forms/)
 * [Active Topics](https://wordpress.org/support/plugin/torro-forms/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/torro-forms/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/torro-forms/reviews/)

## Tags

 * [forms](https://wordpress.org/support/topic-tag/forms/)
 * [function](https://wordpress.org/support/topic-tag/function/)
 * [submission](https://wordpress.org/support/topic-tag/submission/)

 * 6 replies
 * 2 participants
 * Last reply from: [Sven Wagener](https://wordpress.org/support/users/mahype/)
 * Last activity: [9 years, 6 months ago](https://wordpress.org/support/topic/execute-function-on-form-submission/#post-8472056)
 * Status: resolved