PHPackages                             wenprise/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. wenprise/forms

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

wenprise/forms
==============

Extend Nette Forms for WordPress use.

v2.3.5(8mo ago)6796MITPHPPHP &gt;=7.2

Since Dec 30Pushed 3d ago1 watchersCompare

[ Source](https://github.com/iwillhappy1314/wenprise-forms)[ Packagist](https://packagist.org/packages/wenprise/forms)[ RSS](/packages/wenprise-forms/feed)WikiDiscussions master Synced 5d ago

READMEChangelog (10)Dependencies (2)Versions (90)Used By (0)

wenprise-forms
==============

[](#wenprise-forms)

Extend Nette Forms for WordPress use.

Basic usage: [Nette Form](https://doc.nette.org/en/2.4/forms)

Usage
-----

[](#usage)

### Quick start

[](#quick-start)

Forms 类带有自己的HTTP请求处理方法，需要在head\_sent之前实例化，可以把实例化的过程放在 init action 中。

```
add_action('init', function ()
{
    global $form;

    // Get forms object
    $form = Helpers::get_form();
});
```

创建Form实例

```
use Wenprise\Forms\Form;

$form = new Form;

$form->setRenderer(new \Wenprise\Forms\Renders\DefaultFormRender('horizontal'));

// Set form method
$form->setMethod( 'POST' );
$form->setAction('https://www.example.com');

// Set form field
$form->addText('first_name', 'First Name');

// Set submit button
$form->addSubmit( 'send', 'Save' );

// Validate form and get form data
if ( $form->isSuccess() ) {

	$values = $form->getValues();

	$first_name = $values->first_name;

}
```

### Set Required

[](#set-required)

```
$form->addText('first_name', 'First Name')
     ->setRequired();
```

### Add rule

[](#add-rule)

```
$form->addPassword('re_password', 'Password again:')
     ->addRule($form::EQUAL, 'Password mismatch', $form['password']);
```

[Rule Documation](https://doc.nette.org/en/3.0/form-validation)

### Add field description

[](#add-field-description)

```
$form->addText('first_name', 'First Name')
     ->setOption('description', 'This is your first name.');
```

With Html

```
$form->addTextArea('description', Html::el('p')
	->setHtml('This number remains hidden. Terms of service.')
	);
```

### Set condition display

[](#set-condition-display)

```
$form->addColorPicker('first_name3', 'First Name')
     ->setHtmlAttribute('data-cond', '[name=first_name2] == 2');
```

### Multiple Submit Button

[](#multiple-submit-button)

```
$form->addSubmit('save', 'Save');
$form->addSubmit('delete', 'Delete');

if ($form->isSuccess()) {
	if ($form['save']->isSubmittedBy()) {
		....
	}

	if ($form['delete']->isSubmittedBy()) {
		....
	}
}
```

### Use html in label or description

[](#use-html-in-label-or-description)

```
$confirm = Html::el('span')->setHtml('I agree the Terms of service.');

$form->addCheckbox('confirm', $confirm)->setOption('description', $confirm);
```

### Set Datastore

[](#set-datastore)

```
$form->setDatastore(new \Wenprise\Forms\Datastores\PostMetaDatastore(1, $form));

$form->save();
```

Fields
------

[](#fields)

### nonce field

[](#nonce-field)

```
$form->addCsrf('postform', 'Nonce invaliadte');
```

### WordPress Tinymce editor

[](#wordpress-tinymce-editor)

[Settings](https://codex.wordpress.org/Function_Reference/wp_editor)

```
$form->addEditor('post_extra', 'Extra content', []);
```

### Ajax uploader

[](#ajax-uploader)

```
$form->addAjaxUpload('photos', 'Photos', true, )
             ->setUrl(  admin_url( 'admin-ajax.php?action=upload' ) );
```

#### Uploader backend sample.

[](#uploader-backend-sample)

```
add_action('wp_ajax_upload', 'ajax_uploader');
add_action('wp_ajax_nopriv_upload', 'ajax_uploader');

function ajax_uploader()
{

    require_once(ABSPATH . 'wp-admin/includes/image.php');
    require_once(ABSPATH . 'wp-admin/includes/file.php');
    require_once(ABSPATH . 'wp-admin/includes/media.php');

    $attachment_id = media_handle_upload('file', 0);

    $thumb_url  = wp_get_attachment_thumb_url($attachment_id);
    $origin_url = wp_get_attachment_url($attachment_id);

    $thumb = get_post($attachment_id);

    $file_data = [
        'id'       => $attachment_id,
        'original' => $thumb->post_title,
        'size'     => $thumb->size,
        'state'    => 'SUCCESS',
        'title'    => $thumb->post_title,
        'type'     => $thumb->post_mime_type,
        'thumb'    => $thumb_url,
        'url'      => $origin_url,
    ];

    wp_send_json($file_data, 200);

    return false;
}
```

### Slider input

[](#slider-input)

[Setting](http://ionden.com/a/plugins/ion.rangeSlider/en.html)

```
$form->addSlider('price', 'Price', []);
```

### Data Picker

[](#data-picker)

[Setting](https://jqueryui.com/datepicker/)

```
$form->AddBirthdaypicker('_birthday', 'Date of Birth', [
    'format' => 'YYYY-MM-DD',
    'template' => 'YYYY-MM-DD',
    'minYear' => '1900',
    'maxYear' => date("Y")
]);
```

### Color Picker

[](#color-picker)

[Setting](http://automattic.github.io/Iris/)

```
$form->addColorPicker('color', 'Color', []);
```

### Chosen

[](#chosen)

```
$choices = [
    'php'         => 'PHP',
    'javascript'  => 'JavaScript',
    'css'         => 'CSS',
    'java'        => 'Java',
];

$form->addChosen('category', 'Category', $choices);
```

#### Multi Chosen

[](#multi-chosen)

```
$form->addMultiChosen('post_tags', 'Tags', $choices);
```

### Signature Filed

[](#signature-filed)

```
$options = [
   'width'      => '500',
   'height'     => '250',
   'border'     => '#999',
   'background' => '#f3f3f3',
];

$form->addSignature('first_name9', 'First Name', $options);
```

### Star rating input

[](#star-rating-input)

```
$options = [
    'displayOnly' => false,
    'showClear'   => false,
    'theme'       => 'krajee-svg',
    'step'        => 1,
    'min'         => 1,
    'max'         => 5,
];

$form->addStarRating('rating', 'Rating', $options);
```

### Image Select

[](#image-select)

```
$options = [
    'light' => 'https://via.placeholder.com/64/EEEEEE/000000/?text=Light',
    'dark'  => 'https://via.placeholder.com/64/000000/FFFFFF/?text=Dark',
];

$form->addImagePicker('theme', 'Theme', $options);
```

### Autocomplete Input

[](#autocomplete-input)

Source is an array or a url returns an array.

```
$form->addAutocomplete('name', 'Name')->setSource([
    [
        'value' => 'aaa',
        'data'  => 'AAA',
    ],
    [
        'value' => 'bbb',
        'data'  => 'BBB',
    ],
    [
        'value' => 'ccc',
        'data'  => 'CCC',
    ],
]);
```

If Source is an ajax url, the backend need return data as bellow.

```
suggestions: [
  { "value": "United Arab Emirates", "data": "AE" },
  { "value": "United Kingdom",       "data": "UK" },
  { "value": "United States",        "data": "US" }
]
```

### Table input

[](#table-input)

```
$fields = [
    [
        'name'    => 'name',
        'display' => '商品名称',
        'type'    => 'text',
    ],
    [
        'name'    => 'quantity',
        'display' => '数量',
        'type'    => 'text',
    ],
    [
        'name'    => 'price',
        'display' => '单价',
        'type'    => 'text',
    ],
];

$values = [
    [
        'name'     => 'Macbook Pro',
        'quantity' => '1',
        'price'    => '8500',
    ],
    [
        'name'     => 'Pixel XL',
        'quantity' => '2',
        'price'    => '8500',
    ],
];

$form->addTableInput('table', 'Table', [], $fields)
     ->setDefaultValue($values);
```

### Clone Input

[](#clone-input)

Allow input multi text value.

```
$form->addCloneInput('photo1', 'Photo');
```

### Group Input

[](#group-input)

Set a prefix or suffix for text input.

```
$form->addGroupInput('day1', 'Day')
     ->setPrefix('Email')
     ->setSuffix('gmail.com');
```

### SMS input

[](#sms-input)

Send SMS code

```
$form->addSmsInput('phone', 'Cellphone', )
             ->setUrl(admin_url('admin-ajax.php?action=validate_cellpone'));
```

Backend Example

```
/**
 * 发送短信验证码
 */
add_action('wp_ajax_validate_cellpone', 'validate_cellpone');
add_action('wp_ajax_nopriv_validate_cellpone', 'validate_cellpone');
function validate_cellpone()
{
	$phone = Input::get( 'phone', null );

	if ( ! $phone && is_user_logged_in() ) {
		$phone = OpenAuth::get_open_id( 'phone', get_current_user_id() );
	}

	$random = mt_rand( 100000, 999999 );

	// 发送验证码之前，保存验证码到数据库
	$code       = PhoneCode::query()->firstOrCreate( [ 'phone' => $phone ] );
	$code->code = $random;
	$code->save();

	$msg = Helper::send_sms( $phone, $code->code );

	wp_send_json( $msg, '200' );
};

/**
 * 发送短信后端示例，使用云片网API
 */
function send_sms( $mobile, $content )
{
    $config = [
        'apikey' => 'xxxxx',
        'tpl_id' => '123456',
    ];

    // 模板接口网关
    $url = "https://sms.yunpian.com/v2/sms/tpl_single_send.json";

    $args = [
        'body' => [
            'apikey'    => $config[ 'apikey' ],
            'mobile'    => $mobile,

            // 如果是模板短信
            'tpl_id'    => $config[ 'tpl_id' ],
            'tpl_value' => "#code#=$content",
        ],
    ];

    $result = json_decode( wp_remote_retrieve_body( wp_remote_post( $url, $args ) ) );

    // 根据网关返回的数据返回消息
    return [
        'code' => $result->code,
        'msg'  => $result->msg,
    ];
}
```

### Captcha Input

[](#captcha-input)

```
 $form->AddCaptcha('captcha', 'Captcha')
             ->setUrl(admin_url('admin-ajax.php?action=get_captcha'));
```

### Chained Select

[](#chained-select)

```
$form->addChainedSelect('chained', 'Chained Select', [
        'url'        => get_theme_file_uri('cityData.min.json'),
        'selects'    => ['province', 'city', 'area'],
        'emptyStyle' => 'none',
    ], ['province', 'city', 'area'])->setDefaultValue([001, 002, 003]);
```

### Captcha backend sample.

[](#captcha-backend-sample)

```
/**
 * Captcha backend sample.
 * WordPress core do not use sessions, use cookie and transient instead
 *
 * Run composer require gregwar/captcha to install requirement
 */
add_action('wp_ajax_get_captcha', 'get_captcha');
add_action('wp_ajax_nopriv_get_captcha', 'get_captcha');
function get_captcha($type)
{
    header('Content-type: image/jpeg');

    $builder    = new CaptchaBuilder();
    $captcha_id = wp_generate_uuid4();
    $expires = MINUTE_IN_SECONDS * 5;

    setcookie('wprs-security-captcha-id', $captcha_id, time() + $expires);
    set_transient($captcha_id, $builder->getPhrase(), $expires);

    $builder->build()
            ->output();
}
```

```
// 验证Captcha
$captcha_id      = $_COOKIE[ 'wprs-security-captcha-id' ];
$session_captcha = get_transient($captcha_id);
```

###  Health Score

50

↑

FairBetter than 96% of packages

Maintenance82

Actively maintained with recent releases

Popularity18

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor1

Top contributor holds 98.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~32 days

Recently: every ~86 days

Total

87

Last Release

263d ago

Major Versions

v0.1-beta → 1.0.12018-06-04

1.8.9 → 2.0.12023-02-13

PHP version history (3 changes)1.0PHP &gt;=5.6

2.0.1PHP &gt;=8.0

2.2.0PHP &gt;=7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/a0fa49958b7c45c0b373b185feb5debe5bdd35be3b3536bc44477d3bd3a2d435?d=identicon)[iwillhappy1314](/maintainers/iwillhappy1314)

---

Top Contributors

[![iwillhappy1314](https://avatars.githubusercontent.com/u/1455683?v=4)](https://github.com/iwillhappy1314 "iwillhappy1314 (251 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")[![snyk-bot](https://avatars.githubusercontent.com/u/19733683?v=4)](https://github.com/snyk-bot "snyk-bot (2 commits)")

---

Tags

formform-buildernette-formwordpress-forms

### Embed Badge

![Health badge](/badges/wenprise-forms/health.svg)

```
[![Health](https://phpackages.com/badges/wenprise-forms/health.svg)](https://phpackages.com/packages/wenprise-forms)
```

###  Alternatives

[nette/php-generator

🐘 Nette PHP Generator: generates neat PHP code for you. Supports new PHP 8.5 features.

2.2k64.2M576](/packages/nette-php-generator)[symplify/monorepo-builder

Not only Composer tools to build a Monorepo.

5205.3M82](/packages/symplify-monorepo-builder)[nette/code-checker

✅ Nette CodeChecker: A simple tool to check source code against a set of Nette coding standards.

881.7M6](/packages/nette-code-checker)[kdyby/forms-replicator

Nette forms container replicator aka addDynamic

32997.7k6](/packages/kdyby-forms-replicator)[radekdostal/nette-datetimepicker

DatePicker and DateTimePicker input controls for Nette Framework

13272.2k3](/packages/radekdostal-nette-datetimepicker)[uestla/twigrid

Experimental DataGrid for Nette Framework

1712.3k2](/packages/uestla-twigrid)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
