Skip to content

Provides a method to capture simple silverstripe forms and a friendly admin interface for users

License

Notifications You must be signed in to change notification settings

k-coidan/silverstripe-form-capture

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Silverstripe Form Capture

Provides a method to capture simple silverstripe forms and a friendly admin interface for users.

Installation

This version requires silverstripe 4, for 3.1+ compatibility see the 1.* branch.

Either clone/download this repository into a folder named 'silverstripe-form-capture' or run:

composer require andrewhaine/silverstripe-form-capture

Initialisation

After installing you will need to run 'dev/build' and add the module extension to the form class or any subclass of form that you wish to store.

Usage

To store submissions from a form simply add a call to the new method in the function you will use to handle the form. See the example below for usage

Example

In the page controller:

public function MyForm() {
	$fields = FieldList::create(
		TextField('ExampleTextField'),
		TextareaField::create('ExampleTextareaField')
	);

	$actions = FieldList::create(
		FormAction::create('doMyForm', 'Submit')
	);

	$form = Form::create($this, __FUNCTION__, $fields, $actions);

	return $form;
}

public function doMyForm($data, $form) {
	$form->captureForm();

	// Other processing
}

When capturing a form some useful information is returned which can be used in the controller. For example a link is returned to the submission area in the CMS.

$capturedSubmission = $form->captureForm();

echo($capturedSubmission['Link']);
// http://your-site.com/admin/<Link to exact submission>

Options

When calling the captureForm() there are a few optional parameters which will enhance how submission objects are displayed in the CMS.

  • Form Submission Title - A string which will be displayed as the submission title in the admin area (defaults to 'Form Submission').
  • Excluded Fields - An array of field names which will not be stored, this can also be a string containing the name of a single field to exclude.
  • Details Fields - An array of fields which will be included in the 'details' column of the gridfield, this can also be a string containing the name of a single field to include in the details.

Example

$form->captureForm('Contact Form Submission', ['IDontWantThisField', 'OrThisOne'], 'Details');

About

Provides a method to capture simple silverstripe forms and a friendly admin interface for users

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%