Download the PHP package silverstripe/multiform without Composer

On this page you can find all versions of the php package silverstripe/multiform. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package multiform

MultiForm Module

Scrutinizer Code Quality Code Coverage

Introduction

MultiForm is a SilverStripe module, allowing flow control for forms, and step process to be automatically determined based on configuration variables on each step class. It augments the existing Form class in SilverStripe.

The goal of the module is to allow greater flexibility than features, so each individual implementation can be customized to the project requirements.

Maintainer Contact

Requirements

Note: For a SilverStripe 4.x or 3.x compatible version, please use ^2 or ^1 tagged version

What it does do

What it doesn't do

Note: The multiform directory should sit in your SilverStripe root project directory in the file system as a sibling of cms and framework.

Reporting bugs

If you've found a bug that should be fixed for future releases, then please make a ticket on https://github.com/silverstripe/silverstripe-multiform/issues.

This helps to ensure we release less buggy software in the future!

Tutorial

The assumption is the developer who is starting this tutorial has an intermediate level of knowledge in SilverStripe, understands what "run dev/build?flush=1" means, and has written some custom PHP code in SilverStripe before.

If you are not familiar with SilverStripe, it is highly recommended you run through the tutorials before attempting to start with this one.

1. Installing

Using Composer, you can install multiform into your SilverStripe site using this command (while in the directory where your site is currently located)

2. Create subclass of MultiForm

First of all, we need to create a new subclass of MultiForm.

For the above example, our multi-form will be called SurveyForm

3. Set up first step

Now that we've created our new MultiForm subclass step, we need to define what form is going to be the first step in our multi-step process.

Each form step must subclass MultiFormStep. This is so the multi-form can identify that this step is part of our step process, and is not just a standard form.

So, for example, if we were going to have a first step which collects the personal details of the form user, then we might have this class:

Now that we've got our first step of the form defined, we need to go back to our subclass of MultiForm, SurveyForm, and tell it that SurveyFormPersonalDetailsStep is the first step.

4. Define next step, and final step

We've managed to set up the basics of multi-form, but it's not very useful, as there's only one step!

To get more than one step, each step needs to know what it's next step is in order to use flow control in our system.

To let the step know what step is next in the process, we do the same as setting the $start_step variable SurveyForm, but we call it $next_steps.

At the very least, each step also has to have a getFields() method returning a FieldSet with some form field objects. These are the fields that the form will render for the given step.

Keep in mind that our multi-form also requires an end point. This step is the final one, and needs to have another variable set to let the multi-form system know this is the final step.

So, if we assume that the last step in our process is OrganisationDetailsStep, then we can do something like this:

5. Run database integrity check

We need to run dev/build?flush=1 now, so that the classes are available to the SilverStripe manifest builder, and to ensure that the database is up to date with all the latest tables. So you can go ahead and do that.

Note: Whenever you add a new step, you MUST run dev/build?flush=1 or you may receive errors.

However, we've forgotten one thing. We need to create a method on a page-type so that the form can be rendered into a given template.

So, if we want to render our multi-form as $SurveyForm in the Page.ss template, we need to create a SurveyForm method (function) on the controller:

The SurveyForm() function will create a new instance of our subclass of MultiForm, which in this example, is SurveyForm. This in turn will then set up all the form fields, actions, and validation available to each step, as well as the session.

You can of course, put the SurveyForm method on any controller class you like.

Your template should look something like this, to render the form in:

In this case, the above template example is a sub-template inside the Layout directory for the templates. Note that we have also included $Form, so standard forms are still able to be used alongside our multi-step form.

6. Adding a step indicator

By default, we include a couple of basic progress indicators which could be useful, out of the box.

Two of them, as of the time of writing this are:

They are designed to be used either by themselves, or alongside each other. For example, the percentage could compliment the progress list to give an indication of completion status.

To include these with our instance of multiform, we just need to add an <% include %> statement into the template.

For example:

This means the included template is rendered within the scope of the SurveyForm instance returned, instead of the top level controller context. This gives us the data to show the progression of the steps.

Putting it together, we might have something looking like this:

Feel free to play around with the progress indicators. If you need something specific to your project, just create a new "Include" template inside your own project templates directory, and include that instead. Some helpful methods to use on the MultiForm would be:

The default progress indicators make use of the above functions in the templates.

To use a custom method of your own, simply create a new method on your subclass of MultiForm. In this example, SurveyForm would be the one to customise. This new method you create would then become available in the progress indicator template.

7. Loading values from other steps

There are several use cases where you want to pre-populate a value based on the submission value of another step. There are two methods supporting this:

Here is an example of how to populate the email address from step 1 in step2 :

8. Finishing it up

Now that we've got a structure set up to collect form data along each step, and progress through successfully, we need to customise what happens at the end of the last step.

On the final step, the finish() method is called to finalise all the data from the steps we completed. This method can be found on MultiForm. However, we cannot automatically save each step, because we don't know where to save it. So, we must write some code on our subclass of MultiForm, overloading finish() to tell it what to do at the end.

Here is an example of what we could do here:

9. Organisation data model

The class Organisation is mentioned in the above example but doesn't exist at the moment (unlike the existing Member() class which looks after the member groups in SilverStripe) so we need to create it:

This example has been chosen as a separate DataObject but you may wish to change the code and add the data to the Member class instead.

Warning

If you're dealing with sensitive data, it's best to delete the session and step data immediately after the form is successfully submitted.

You can delete it by calling this method on the finish() for your MultiForm subclass:

This will also go through each of it's steps and delete them as well.

Customising

Because the multi-form system doesn't magically do everything for you, although it does provide a sensible set of defaults, it means you need to customise certain aspects of it. Here are some useful methods that can be customised (although you can technically overload anything available on MultiForm and MultiFormStep!):

Templates

The best part about this system is the freedom to customise each form step template.

In order, when you have a page with a multi-form rendering into it, it chooses which template to render that form in this order, within the context of the MultiForm class:

More than likely, you'll want the first one to be available when the form renders. To that effect, you can start placing templates in the templates/Includes directory for your project. You need to name them the same as the class name for each step. For example, if you want MembershipForm, a subclass of MultiFormStep to have it's own template, you would put MembershipForm.ss into that directory, and run ?flush=1.

If you'd like a pre-existing template on how to customise the form step, have a look at Form.ss that's found within the framework module. Use that template, as a base for your new MembershipForm.ss template in your project templates.

For more information on this, please look at the Form documentation.

getNextStep()

If you are wanting to override the next step (for example if you want the next step to be something different based on a user's choice of input during the step) you can override getNextStep() on any given step to manually override what the next step should be. An example:

Validation

To define validation on a step-by-step basis, please define getValidator() and return a Validator object, such as RequiredFields - for more information on form validation see :form.

e.g.

finish()

finish() is the final call in the process. At this step, all the form data would most likely be unserialized, and saved to the database in whatever way the developer sees fit. By default, we have a finish() method on MultiForm which serializes the last step form data into the database, and that's it.

finish() should be overloaded onto your subclass of MultiForm, and parent::finish() should be called first, otherwise the last step form data won't be saved.

For example:

The above is a sample bit of code that simply fetches all the steps in the database that were saved. Further refinement could include getting steps only if the Data (serialized raw form data) is set, as the above example doesn't respect branching of steps (multiple next steps on a given form step).

Best practices

Delete session after submission

If you're dealing with sensitive data, such as credit card fields, or personal fields that shouldn't be lying around in the session database, then it's a good idea to immediately delete this data after the user has submitted.

This can be easily achieved by adding the following line at the end of your finish() method on your MultiForm subclass.

Expiring old session data

Included with the MultiForm module is a class called MultiFormPurgeTask. This task can be used to purge expired session data on a regular basis. The date of expiry can be customised, and is given a default of 7 days to delete sessions after their creation.

You can run the task from the URL, by using http://mysite.com/dev/tasks/MultiFormPurgeTask?flush=1

MultiFormPurgeTask is a subclass of BuildTask, so can be run using the SilverStripe CLI tools.

One way of automatically running this on a UNIX based machine is by cron.

TODO

Related


All versions of multiform with dependencies

PHP Build Version
Package Version
Requires silverstripe/framework Version ^4
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package silverstripe/multiform contains the following files

Loading the files please wait ....