2017 © Pedro Peláez
 

silverstripe-vendormodule silverstripe-formpreserve

Easily preserve and clear user entered form data contents via session in the event of errors

image

vulcandigital/silverstripe-formpreserve

Easily preserve and clear user entered form data contents via session in the event of errors

  • Friday, February 23, 2018
  • by vulcandigital
  • Repository
  • 2 Watchers
  • 0 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

silverstripe-formpreserve

Easily preserve and clear user entered form data contents via session in the event of errors, (*1)

Requirements

  • silverstripe/framework: ^4

Usage

class YourForm extends Form 
{
    private static $extensions = [
        FormPreserveExtension::class
    ];

    public function __construct(RequestHandler $controller = null, $name = self::DEFAULT_NAME, FieldList $fields = null, FieldList $actions = null, $validator = null)
    {
        /** @var ArrayData $preserved */
        $preserved = $this->retrievePreserved();

        $fields = FieldList::create([
            TextField::create('FirstName', 'First name:', $preserved->FirstName)->setAttribute('required', true),
            EmailField::create('Email', 'Your email:', $preserved->Email)->setAttribute('placeholder', 'Where do we send our response?')->setAttribute('required', true),
        ]);

        $actions = FieldList::create([
            FormAction::create('doSubmit', 'Send')->setUseButtonTag(true)->setButtonContent('<i class="fal fa-paper-plane"></i> Send')->addExtraClass('btn btn-primary')
        ]);

        parent::__construct($controller, $name, $fields, $actions, $validator);
    }
}

Your form submit action:, (*2)

class ContactPageController extends \PageController 
{
   public function doSubmit($data, Form $form)
    {
        FormPreserve::preserve($form, $data);

        if (!isset($data['Email']) || !filter_var($data['Email'], FILTER_VALIDATE_EMAIL)) {
            return $this->redirectBack();
        }

        FormPreserve::clear($form);
        return $this->redirectBack();
    }
}

The Versions

23/02 2018

dev-master

9999999-dev

Easily preserve and clear user entered form data contents via session in the event of errors

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

23/02 2018

1.0.0

1.0.0.0

Easily preserve and clear user entered form data contents via session in the event of errors

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires