Torro Forms // Using Form Action API

For adding your own Action, the class Torro_Form_Action have to be extended by your own class. 

The Torro Forms action API adds a tab to the actions section in the form. With the option_content() method you can add your HTML for your action options, which you can save in the save() method of the class.

The Torro Forms action API comes with the functions handle() and notification(). The handle() function will be executed in directly after  the user has submitted the form, all data was saved and before the first chars will be displayed. There you can do things like redirections or other stuff. The notification() function will be executed in the content section of the page which will be shown after a user has submitted the form.

This page contains the technical documentation for the Torro Form Action API and is written for developers. If you're not a developer you may want to review the Form Actions.

Default Usage

class My_Action extends Torro_Form_Action{
    /**
     * Sets up the contol name etc
     */
    protected function init() {
        $this->title = __( 'My Action', 'torro-forms' );
        $this->name = 'my_acl';
        $this->option_name = __( 'My Action', 'torro-forms' );
    }
	
    /**
     * The content of the widget, displayed in formbuilder if control is selected
     *
     * @param int $form_id
     * @return string $html
     */
    public function option_content( $form_id ) {
        // HTML content for action tab in admin
    }
	
    /**
     * Saving the data of the option content in the formbuilder
     *
     * @param int $form_id
     */
    public function save( $form_id ) {
    	// Save your options
    }
	
    /**
     * Getting data before sending headers
     *
     * @param int $form_id
     * @param int $response_id
     * @param array $response
     * @return boolean $has_access
     */
    public function handle( $form_id, $response_id, $response ) {
        // Do whatever you want with the response
    }
    
    /**
     * Getting data on displaying content
     *
     * @param int $form_id
     * @param $int $response_id
     * @param array $response
     *
     * @return string $html
     */
    public function notification( $form_id, $response_id, $response ){
    	// Content the user have to see after submitting
    }
}

Registering the action

    torro()->actions()->register( 'My_Action' );

Example

class My_Action extends Torro_Form_Action {
    /**
     * Sets up the contol name etc
     */
    protected function init() {
	    $this->title = __( 'My Action', 'torro-forms' );
	    $this->name = 'my_action';
    }
	
    /**
     * The content of the action, displayed in formbuilder
     *
     * @param string $html
     */
    public function option_content( $form_id ) {
        $redirect_to_google = get_post_meta( $form_id, 'redirect_to_google', true );
        
        if( 'yes' == $redirect_to_google )
            $checked = ' checked="checked"';
    
        $html = 'This are my option settings.';
        $html.= '<input type="checkbox" name="redirect_to_google" value="yes"' . $checked . '> Redirect to google';
        
        return $html;
    }
	
    /**
     * Saving the data of the option content in the formbuilder
     *
     * @param int $form_id
     */
    public function save( $form_id ) {
    	update_post_meta( $form_id, 'redirect_to_google', $_POST[ 'my_acl_has_access' ] );
    }
	
    /**
     * Getting data before sending headers
     *
     * @param int $form_id
     * @param int $response_id
     * @param array $response
     * @return boolean $has_access
     */
    public function handle( $form_id, $response_id, $response ) {
        $redirect_to_google = get_post_meta( $form_id, 'redirect_to_google', true );
    
        if( 'yes' == $redirect_to_google ) {
            wp_redirect( 'https://google.com' );
        }
    }
}
torro()->actions()->register( 'My_Action' );

How to add your code

To add your code, we have created your the function torro_load(). Put in your function to the parameters and it will be loaded in the right way.

function your_torro_functionality(){
    require_once 'my-element-type.php';

// Also take care of the other functionality here,
// like registering the template location. } function my_plugin() { if ( ! function_exists( 'torro_load' ) ) { return; // Torro Forms is not active } torro_load( 'your_torro_functionality' ); } add_action( 'plugins_loaded', 'my_plugin' );
Fork me on GitHub