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

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

Containers are collectors for elements. They will contain the content of pages of a form. There are some basic functions to handle containers with the torro() function. Here is a list of the most important functions.

    torro()->containers()->create( $form_id, $args );
    torro()->containers()->update( $container_id, $args );
    torro()->containers()->get( $container_id );
    torro()->containers()->delete( $container_id );
    torro()->containers()->exists( $container_id );
torro()->containers()->copy( $container_id, $to_form_id );

Create a container

Parameters

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

    
    $args = array(
        'label' => 'Page 1',
        'sort'	=> 0,
    );
    $container = torro()->containers()->create( $form_id, $args );

Return Values

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

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

Update a container

Parameters

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

    $args = array(
        'label' => 'Page 2',
        'sort' => 1
    );
    $form = torro()->containers()->update( $container_id, $args );

Return Values

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

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

Getting container data

Parameters

To get a container you can use the following code.

    $container = torro()->containers()->get( $container_id );

Return Values

You will get back a Torro_Container 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 container class to see which further properties and methods you also can access or try out the autocomplete functionality of your programming IDE.

    $elements = torro()->containers()->get( $container_id )->elements;

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

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

Deleting a container

Parameters

Input the container ID to the function delete.

    $deleted = torro()->containers()->delete( $container_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 a container

Parameters

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

    torro()->container()->copy( $container_id, $form_id );

Return Values

The function return a Torro_Container object or a WP_Error.

Fork me on GitHub