Torro Forms // Using Form Settings API

For adding your own settings, the class Torro_Form_Setting have to be extended by your own class.

The Torro Form settings API adds a Tab in the settings section of the form. There you can ad your form settings HTML. Also you have the save() function where you can do your save functionalities for saving the options of the option_content() code.

With the settings you are free to do anything with the form. Control the form by using Torro Forms action hooks or do anything else with the form. 

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

Default Usage

class My_Setting extends Torro_Form_Setting {
    /**
     * Sets up the contol name etc
     */
    protected function init() {
    	$this->option_name = $this->title = __( 'My Form Setting', 'torro-forms' );
    	$this->name = 'my_form_setting';
    }
    
    /**
     * Option content
     *
     * @param int $form_id
     *
     * @return string $html
     */
    public function option_content( $form_id ) {
        // HTML content for settings tab in formbuilder
    }
	
    /**
     * Saving data
     *
     * @param int $form_id
     */
    public function save( $form_id ) {
    	// Save your options
    }
}

Registering the setting

    torro()->form_settings()->register( 'My_Setting' );

Example

class My_Setting extends Torro_Form_Setting {
    /**
     * Sets up the contol name etc
     */
    protected function init() {
    	$this->option_name = $this->title = __( 'My Form Setting', 'torro-forms' );
    	$this->name = 'my_form_setting';
    }
    
    /**
     * Option content
     *
     * @param int $form_id
     *
     * @return string $html
     */
    public function option_content( $form_id ) {
        $my_value = get_post_meta( $form_id, 'my_value', true );
        
        $html = '<labe for="my_value">This are my option settings.&lgt;/label>';
        $html.= '<input type="checkbox" id="my_value" name="my_value" value="' . $my_value . '" />';
        
        return $html;
    }
	
    /**
     * Saving data
     *
     * @param int $form_id
     */
    public function save( $form_id ) {
    	$start_date = $_POST[ 'start_date' ];
    	update_post_meta( $form_id, 'start_date', $start_date );
    }
}

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