Torro Forms // Using torro()->elements()

This page contains the technical documentation for the Torro Forms torro() functions and is written for developers. If you're not a developer you may want to review the Form Builder.

Base functions

There are some basic functions to handle elements with the torro() function. Here is a list of the most important functions.

    torro()->elements()->create( $container_id, $args );
    torro()->elements()->update( $element_id, $args );
    torro()->elements()->get( $element_id );
    torro()->elements()->delete( $element_id );
    torro()->elements()->exists( $element_id );
    torro()->elements()->copy( $element_id, $container_id );
    torro()->elements()->register( $element_class_name );

Create an element

Parameters

The create() function needs the parameter $container_id and $args. The parameter $args contains an array with the data for the element. The function will give back the element object or a WP_Error.

    
    $args = array(
        'type'	=> 'textfield',
        'label'	=> 'Name',
        'sort'	=> 0,
    );
    $element = torro()->elements()->create( $container_id, $args );

Return Values

You will get back a Torro_Element object by this function. To get the ID of the created element, get the variable of the object by using $element->id. To catch all eventually occured errors, you have to check if $element is a WP_Error and print out the error message.

    if( ! is_wp_error( $element ) ) {
        $element_id = $element->id;
    } else {
        echo $element->get_error_message();
    }

Update an element

Parameters

The update() function needs the parameters $element_id and $args. The $args parameter contains an array with the data for the element. The function will give back the element object or an WP_Error.

    $args = array(
'type' => 'textfield' 'label' => 'Surname', 'sort' => 1 ); $element = torro()->elements()->update( $element_id, $args );

Return Values

You will get back a Torro_Element child object by this function. To get the ID of the created element, get the variable of the object by using $element->id. To catch all eventually occured errors, you have to check if $element is a WP_Error and print out the error message.

    if( ! is_wp_error( $element ) ) {
        $element_id = $element->id;
    } else {
        echo $element->get_error_message();
    }

Getting element data

Parameters

To get an element you can use the following code.

    $element = torro()->elements()->get( $element_id );

Return Values

You will get back a Torro_Element child object by this function. To get further information you can also use the deeper chained functions to access the container object parameters. Take a look at our autocomplete functionality of your programming IDE.

    $answers = torro()->elements()->get( $element_id )->answers;

To catch all eventually occured errors, you have to check if $element is a WP_Error and print out the error message.

    if( ! is_wp_error( $element ) ) {
        $element_id = $element->id;
    } else {
        echo $element->get_error_message();
    }

Deleting an element

Parameters

Input the element ID to the function delete.

    $deleted = torro()->elements()->delete( $element_id );

Return Values

To catch all eventually occured errors, you have to check if $deleted is a WP_Error and print out the error message.

    if( is_wp_error( $deleted ) ) {
        echo $deleted->get_error_message();
    }

Checking existance of a container

Parameters

Input the form ID to the function exists.

    torro()->container()->exists( $container_id );

Return Values

The function returns true if the container exists and false if not.

Copy an element

Parameters

To copy an element from one container to another, put in the $element_id which have to be copied and the $container_id where to copy the element. The element and all the content of the element will be copied to the container.

    torro()->elements()->copy( $element_id, $container_id );

Return Values

The function return a Torro_Element object or a WP_Error.

Register an element

Parameters

For creating an own element it have to be registered.

    torro()->elements()->register( 'Element_Class_Name' );

Return Values

The function return a Torro_Element object or a WP_Error.

Fork me on GitHub