PHPackages                             trendwerk/acf-forms - 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. trendwerk/acf-forms

ArchivedLibrary

trendwerk/acf-forms
===================

Helper to use ACF forms in the front-end.

0.2.0(5y ago)5712↓100%3GPL-3.0+PHPPHP &gt;=7.1CI failing

Since Mar 8Pushed 5y ago2 watchersCompare

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

READMEChangelog (2)DependenciesVersions (3)Used By (0)

ACF Forms
=========

[](#acf-forms)

**Active development for this package has been discontinued.**

Helper package to use ACF forms in the front-end. What it does:

- Adds the ability to send notifications
- A default "Admin" notification
- Saves entries to the database
- Adds a wrapper around [`acf_form`](https://www.advancedcustomfields.com/resources/acf_form/) that does the repetitive work

**This package requires [Advanced Custom Fields Pro](https://www.advancedcustomfields.com/pro/) v5 to be installed.**

Quick links: [Install](#install) | [Usage](#usage) | [Options](#options) | [Example](#example)

Install
-------

[](#install)

```
composer require trendwerk/acf-forms
```

Usage
-----

[](#usage)

Creating and showing a form with this package consists of four parts:

1. [Initialize package](#initialize)
2. [Create field group](#create-field-group)
3. [Register form](#register-form)
4. [Render form](#render)

### Initialize

[](#initialize)

```
$acfForms = new \Trendwerk\AcfForms\AcfForms();
$acfForms->init();
```

This code should be run when bootstrapping your theme (traditionally done via `functions.php`). Initialization creates the `entries` post type and sets up defaults form handlers and notifications.

### Create field group

[](#create-field-group)

Create a new field group in Advanced Custom Fields. When choosing a location where to show this field group, make sure you use `Forms > Front-end` is equal to `Yes`.

### Register form

[](#register-form)

```
$acfForms->register($name, $options);
```

ParameterDefaultRequiredDescription`$name``null`Yes(Unique) name / slug of the form`$options``null`YesArray with options. See [Options](#options). **`field_groups` is a required property.**### Render

[](#render)

Rendering a form consists of two parts:

- Displaying the form
- Handling form data and enqueue-ing scripts (`Form::head()`)

For example:

```
use Trendwerk\AcfForms\Form\Form;

Form::head();
...
$form = new Form($name);
$form->render();
```

In reality, the `render` method will be called somewhere inside your actual template.

Options
-------

[](#options)

ParameterDefaultRequiredDescription`acfForm``null`YesOptions passed to the [`acf_form`](https://www.advancedcustomfields.com/resources/acf_form/) function. **`field_groups` is a required property.**`label``null`NoLabel used in the e-mail subject and entry title. If left empty, the unique form name will be used`notifications``['Trendwerk\\AcfForms\\Notification\\Admin']`NoNotifications that are sent via e-mail after form submission. See [Notifications](#notifications)### Notifications

[](#notifications)

Notifications can be created by extending the [`Notification`](https://github.com/trendwerk/acf-forms/blob/master/src/Notification/Notification.php) abstract class or the default [`Admin`](https://github.com/trendwerk/acf-forms/blob/master/src/Notification/Admin.php) notification class.

Example
-------

[](#example)

The example below walks through all three steps of creating and showing a form, based on a field group. This example uses [Twig](https://github.com/twigphp/Twig), [Timber](https://github.com/timber/timber) and [Sphynx](https://github.com/trendwerk/sphynx).

#### `functions.php`

[](#functionsphp)

```
$acfForms = new \Trendwerk\AcfForms\AcfForms();
$acfForms->init();

$acfForms->register('contact', [
    'acfForm'          => [
        'field_groups' => ['group_565474dcb9dd0'],
    ],
    'label'            => 'Contact',
]);
```

Field group keys can be found when showing the `slug` of the field group or in the corresponding JSON file.

#### `page-contact.php`

[](#page-contactphp)

```
