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

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 forms with the torro() function. Here is a list of the most important functions.

    torro()->forms()->create( $args );
    torro()->forms()->update( $form_id, $args );
    torro()->forms()->get( $form_id );
    torro()->forms()->get_current();
    torro()->forms()->get_current_form_id();
    torro()->forms()->delete( $form_id );
    torro()->forms()->exists( $form_id );

Create a form

Parameters

The create() function needs the parameter $args. The parameter contains an array with the data for the form. At the moment it's only the parameter "title" which can be set and have to be set. The function will give back the form object or an WP_Error.

    $args = array(
        'title' => 'My Form'
    );
    $form = torro()->forms()->create( $args );

Return Values

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

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

Update a form

Parameters

The update() function needs the parameters $form_id and $args. The $args parameter contains an array with the data for the form. At the moment it's only the parameter "title" which can be set and have to be set. The function will give back the form object or an WP_Error.

    $args = array(
        'title' => 'My Form'
    );
    $form = torro()->forms()->update( $form_id, $args );

Return Values

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

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

Getting form data

Parameters

To get a form you can use the following code.

    $form = torro()->forms()->get( $form_id );

Return Values

You will get back a form object by this function. To get further information you can also use the deeper chained functions to access the form object parameters. Take a look at our form class to see which further properties and methods you also can access or try out the autocomplete functionality of your programming IDE.

    $containers = torro()->forms()->get( $form_id )->containers;

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

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

Deleting a form

Parameters

Input the form ID to the function delete.

    $deleted = torro()->forms()->delete( $form_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 form

Parameters

Input the form ID to the function exists.

    torro()->forms()->exists( $form_id );

Return Values

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

Fork me on GitHub