PHPackages                             qteab/qterest - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. qteab/qterest

ActiveWordpress-plugin[API Development](/categories/api)

qteab/qterest
=============

QTE Rest adds new endpoints for the Wordpress API

v1.7.0(2y ago)28[4 PRs](https://github.com/qteab/qterest/pulls)PHP

Since Nov 20Pushed 2y ago4 watchersCompare

[ Source](https://github.com/qteab/qterest)[ Packagist](https://packagist.org/packages/qteab/qterest)[ RSS](/packages/qteab-qterest/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (7)Versions (64)Used By (0)

QTE Rest
========

[](#qte-rest)

[![Actions Status](https://github.com/qteab/qterest/workflows/PHP%20CS/badge.svg)](https://github.com/qteab/qterest/workflows/PHP%20CS/badge.svg)[![Actions Status](https://github.com/qteab/qterest/workflows/PHPUnit/badge.svg)](https://github.com/qteab/qterest/workflows/PHPUnit/badge.svg)

This plugin can be used for making forms, newsletter signup (mailchimp) and search.

Installation
------------

[](#installation)

Follow these steps to install the plugin.

1. Download the [latest release](https://github.com/qteab/qterest/releases/latest) as a zip.
2. Go over to your wordpress admin panel.
3. Go to "Plugins" and "Add New"
4. Press "Upload Plugin" and select the file you downloaded earlier.

The plugin is now installed.

Contact
-------

[](#contact)

This part of the plugin handles the forms.

### Creating forms

[](#creating-forms)

Creating forms can be done with `qterest_render_form(array $args, bool $echo = true)`

#### Arguments (array)

[](#arguments-array)

The following arguments are accepted

```
$args = [
    'wrapper_class' => "qterest-form-container", // (string) Overrides the default wrapper class
    'form_class' => "qterest-form", // (string) Overrides the default form class
    'form_row_class' => "qterest-form-row", // (string) Overrides the default form row class
    'form_misc_class' => "qterest-form-misc", // (string) Overrides the default form misc class
    'form_title' => "Contact form", // (string) Adds a h3-tag with the given content
    'error_messages_class' => "qterest-error-messages", // (string) Overrides the default error message class
    'success_message_class' => "qterest-success-messages", // (string) Overrides the default success message class
    'form_fields_class' => "qterest-form-fields", // (string) Overrides the default form fields class
    'submit_label' => __("Submit", 'qterest'), // (string) Overrides the default submit label
    'submit_class' => 'button submit', // (string) Overrides the default submit class
    'fields' => $fields, // (array) Check the next section
]
```

#### Fields

[](#fields)

The following fields are accepted

```
$fields = [
    [
        'type' => 'text', // REQUIRED (string) Possible values are text, email, file, tel, hidden and textarea
        'name' => 'my_text_field', // REQUIRED (string) HTML Attribute name
        'placeholder' => 'Text', // (string) HTML Attribute placeholder
        'value' => 'some_value', // (string) HTML Attribute value
        'label' => 'Text', // (string) Label text
        'class' => 'form-control', // (string) Overrides default class
        'required' => true, // (string) Is the field required?
        'toggles_on' => 'my_checkbox_field', // (string) The id of the field that you want to toogle this field
    ],
    [
        'type' => 'checkbox', // REQUIRED (string) Possible values are checkbox and radio
        'name' => 'my_checkbox_field', // REQUIRED (string) HTML Attribute name
        'value' => 'yes', // (string) HTML Attribute value
        'label' => 'Checkbox', // (string) Label text
        'class' => 'form-control', // (string) Overrides default class
        'toggles' => true, // (bool) Can this field toggle other fields? ONLY checkbox
    ],
    [
        'type' => 'select', // REQUIRED (string) Possible values are select
        'name' => 'my_text_field', // REQUIRED (string) HTML Attribute name
        'placeholder' => 'Text', // (string) HTML Attribute placeholder
        'value' => 'some_value', // (string) HTML Attribute value
        'label' => 'Text', // (string) Label text
        'class' => 'form-control', // (string) Overrides default class
        'toggles_on' => 'my_checkbox_field', // (string) The id of the field that you want to toogle this field
        'options' => [
            [
                'name' => 'My first option', // REQUIRED (string) The name of this option
                'value' => 'my_first_option', // REQUIRED (string) The value of this option
            ],
            [
                'name' => 'My second option', // REQUIRED (string) The name of this option
                'value' => 'my_second_option', // REQUIRED (string) The value of this option
            ]
        ]
    ],
]
```

#### Misc

[](#misc)

It's also possible to put misc in the fields array. These miscs are accepted

```
$fields = [
	[
		'type' => 'title',
		'text' => 'Hejsan',
		'size' => '3' // This will be a h3 element
	],
	[
		'type' => 'paragraph',
		'text' => 'Lorem ipsum dolor sit'
	],
	[
		'type' => 'link',
		'href' => 'https://google.com',
		'text' => 'Google.se'
	]
]
```

#### Example form

[](#example-form)

This is a example of a very basic contact form

```
qterest_render_form([
    'form_title' => 'Simple contact form',
    'submit_label' => __('Send', 'text_domain')
    'fields' => [
        [
            'type' => 'text',
            'name' => 'name',
            'label' => 'Name',
            'placeholder' => 'Sven Svensson',
        ],
        [
            'type' => 'email',
            'name' => 'email', // This field is required by the plugin
            'label' => 'Email *',
            'required' => true,
            'placeholder' => 'sven.svensson@company.com',
        ],
        [
            'type' => 'textarea',
            'name' => 'message',
            'label' => 'Message',
            'placeholder' => 'Hello! I have a question about...',
        ],
        [
            'type' => 'checkbox',
            'name' => 'gdpr',
            'label' => 'I agree to the following terms',
            'required' => true,
        ]
    ]
]);
```

### Filters and Actions

[](#filters-and-actions)

There is a few filters and actions available for you to customize som things

#### Messages

[](#messages)

Example for customizing messages

```
function theme_custom_qterest_messages($messages, $params) {

	$messages['success'] = __("Thank you! We will contact you as soon as possible!", 'text_domain');

	return $messages;

}
add_filter('qterest_contact_messages', 'theme_custom_qterest_messages', 10, 2);
```

The following messages can be changed

- name\_empty
- email\_empty
- email\_invalid
- failed
- success
- mail\_subject
- mail\_body
- mail\_to

Form submission data can be accessed through the `$params` parameter

#### Filter to remove attachments after request

[](#filter-to-remove-attachments-after-request)

You can use the following filter to remove attachments after a request

```
function theme_remove_attachment_after_request($remove, $params, $post_id) {
	// You may access $params or $post_id if you wish to remove attachments conditionally
    $remove = true;
	return $remove;
}
add_filter('qterest_contact_remove_attachments_after_request', 'theme_remove_attachment_after_request', 10, 3);
```

#### Formatting keys (ADMIN)

[](#formatting-keys-admin)

When looking at a contact request you can see that the name of the field identifies the value. This can be changed by adding a filter to display a better name for the customer. The filter name looks like this `qterest_format_key_${key}`.

```
function theme_format_keys_bulk($key) {
    return "Does this person have a dog?";
}
add_filter('qterest_format_key_has_dog', 'theme_format_key_has_dog');
```

You can also bulk format keys with the filter `qterest_format_bulk_keys`.

```
function theme_format_bulk_keys($key) {
    return [
        'has_dog' => "Does this person have a dog?",
        'email' => __("Email address", 'text_domain'), // TIP: You can use localization here if the site is multi language
    ]
}
add_filter('qterest_format_bulk_keys', 'theme_format_bulk_keys');
```

#### Fields

[](#fields-1)

You can change the HTML of the fields with this filter. The filter name looks like this `qterest_contact_field_${field_type}_html`

Example of custom checkbox field

```
function theme_custom_checkbox_field_html($field, $args) {
    $newField = "$args[label]";
    $newField = "
