2017 © Pedro Peláez
 

wordpress-plugin wp-forms

Create forms in using code in WordPress

image

frozzare/wp-forms

Create forms in using code in WordPress

  • Wednesday, August 23, 2017
  • by fredrikforsmo
  • Repository
  • 1 Watchers
  • 9 Stars
  • 1,966 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 9 Open issues
  • 1 Versions
  • 3 % Grown

The README.md

Forms Build Status

Requires PHP 5.6 and WordPress 4.3, (*1)

Create forms in using code in WordPress., (*2)

Installation

composer require frozzare/wp-forms

Example

// Add custom field.
forms()
    ->add_field( 'custom', function ( $attributes ) {
        return sprintf( '

, (*3)

', $attributes['name'] ); } ); // Add form. forms() ->add( 'contact', [ 'name' => [ 'label' => 'Name', 'rules' => 'required|max:250' ], 'email' => [ 'label' => 'Email', 'type' => 'email', 'rules' => 'required|email' ], 'custom' => [ 'label' => 'Custom', 'type' => 'custom' ], 'text' => [ 'label' => 'Text', 'type' => 'textarea' ], 'color' => [ 'label' => 'Select color', 'type' => 'select', 'items' => [ [ 'text' => 'Blue', 'value' => 'blue', ], [ 'text' => 'Green', 'value' => 'green' ] ] ] ] ) ->button( 'Send' ) ->save( function ( array $data ) { // Do something with the data... // Return true if you will save or email the data yourself // otherwise false to save in forms data post type. return false; } ); // Get errors. $errors = forms()->errors( 'contact '); // Render form. forms() ->render( 'contact' );

Save form with ajax

Example, (*4)

$('.form-submit').on('click', function (e) {
    e.preventDefault();

    $.post('/forms-ajax/?action=save&form=contact', $('form').serialize(), function (res) {
        // res.success is true or false
        // res.errors contains all errors if any.
    });
});

Validation rules

alpha, alpha_num, array, between, bool, digit, email, float, int,
ip, min, max, numeric, required, size, string, url

Contributing

Everyone is welcome to contribute with patches, bug-fixes and new features., (*5)

License

MIT © Fredrik Forsmo, (*6)

The Versions

23/08 2017

dev-master

9999999-dev https://github.com/frozzare/wp-forms

Create forms in using code in WordPress

  Sources   Download

MIT

The Requires

 

The Development Requires

plugin wordpress