• Resolved mheiduk

    (@mheiduk)


    Hi,

    I’ve tried to extend the action module with my own module for sending the submission data to an API. I don’t want to create a separate plugin for that, so I’ve extended my functions.php file with this code:

    <?php
    
    class NewsletterApi extends awsmug\Torro_Forms\Modules\Actions\Action {
        protected function bootstrap() {
    	$this->slug  = 'newsletter-api';
    	$this->title = 'Newsletter API';
        }
    	
        public function handle( $submission, $form ) {
            wp_die($submission);
        }
    }
    
    torro()->modules()->actions()->register( 'newsletterapi', 'NewsletterApi' );

    For testing purposes I wanted to show the submission data after submitting the form with wp_die, but nothing happens.

    Would be great if you can give me a hint!

    Best,
    Marc

    • This topic was modified 6 years, 3 months ago by mheiduk.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Sven Wagener

    (@mahype)

    Hi Marc,

    can you try to wrap the torro function into the torro_loaded actionhook?

    Like this example:

    add_action( 'torro_loaded', function() {
       torro()->modules()->actions()->register( 'newsletterapi', 'NewsletterApi' );
    });
    
    • This reply was modified 6 years, 3 months ago by Sven Wagener.
    Thread Starter mheiduk

    (@mheiduk)

    Hi Sven,

    unfortunately this approach does not work either.

    Is there a simple example which will definitely work? I think that another module for this kind of behaviour would be great when already bundled with torro forms.

    Best,
    Marc

    Plugin Author Sven Wagener

    (@mahype)

    OK! Ich will check this out later and will come back with code which works.

    Thread Starter mheiduk

    (@mheiduk)

    Hi Sven,

    I hope you had great holidays! Any updates on this matter? ??

    Best,
    Marc

    Plugin Author Sven Wagener

    (@mahype)

    Hi Marc!

    sorry about the late answer! Here is a complete working example for an extension.

    class NewsletterApi extends awsmug\Torro_Forms\Modules\Actions\Action {
    	protected function bootstrap() {
    		$this->slug  = 'newsletter-api';
    		$this->title = 'Newsletter API';
    	}
    
    	public function handle( $submission, $form ) {
    		// your code
    	}
    
    	public function  enabled( $form ) {
    		return true;
    	}
    }
    add_action( 'init', function() {
    	torro()->modules()->actions()->register( 'newsletterapi', 'NewsletterApi' );
    });
    
    Thread Starter mheiduk

    (@mheiduk)

    Hi Sven,

    thank you, works great!
    I am getting the values from the form in an array via $submission->get_element_values_data(). Is there a better way? Instead of numbers it would be great if I can read the values in the array with predefined keys.

    Best,
    Marc

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Sending submission data to an API’ is closed to new replies.