Using a form to create new pages or overwrite existing pages
_create can be defined as part of a form to have new page(s) created on form submit or overwrite (an) existing page(s).
mwtemplate = Name of a template to use as content for the new page. If you have a form with only one input element you can also use mwtemplate="wsnone". This will take the content of the form input element and make it the source content of the new page (without putting it inside a template).
mwwrite = Full name of the target page
mwfollow = Will send the user to the newly create page after for submission
mwoption can hold three different values:
- "add_random" = Create random numbers
- "next_available" = Get the next available number. If mwwrite is : "orders/", this option will find the highest orders number (e.g. orders/192) and will create a page with one number higher (e.g. orders/193)
- "range:" = Get the next available free slot in a range of numbers. If mwwrite is : "orders/", this option will find the first free spot in a range of numbers. If mwoption="range:2019000-2019999" and mwwrite="orders/" then FlexForm will start looking for a page called orders/2019000. If exists it will look for orders/2019001 etc.. till the first free page is found.
mwleadingzero can be used in combination with range. When a range is set like 1-99999 using mwleadingzero will use the length of the end range and use it to fill the start range with leading zeros, making the range from 00001-99999.
mwfields = comma separated names of form elements that need to be included. Only works when using multiple _create.
If you are creating multiple pages and want to re-assign form fields to template variables, you still add the form field name to mwfields, but add "::" and then the name of the template variable. So if you want to tell mwfields to use formfield "name2", but add it to the template as "Name", add : "name2::Name" to mwfields.
mwslot = name of a specific content slot to use.
nooverwrite = when this is set, no create will be done for a page that already exists. Even if you are creating a new slot for a page that already exist.
noseo = when this is set, even if the setting create-seo-titles in your local settings is set to true to always create SEO friendly page titles, it will not make the title of a new page SEO friendly, but use the title given.
There are several ways for creating a page with FlexForm.
- Easiest Use mwtemplate and mwwrite as described above (and optionally wsfollow, wsoption, etc) This will use the values of mwtemplate and mwwrite and any form elements the current for has and create a new page with template "mwtemplate" and title of "mwwrite". See example 1.
- More advanced and possibilities Use mwtemplate and mwwrite with more options than described above (and optionally wsfollow, wsoption, etc) mwwrite can use can use other elements in the form and use those values to create a title for a new page. Field names can be added using square brackets. So if a form also has a text input field of "title" mwwrite could be "[title]". [mwrandom] can also be used e.g. mwwrite="[title]/[mwrandom]". See example 2.
- Create multiple pages with one form and control what form elements are used. This is where mwfields comes in. This is a comma separated list of form elements that will be used to create the new page. If a form has 15 text input fields, then using _create will include all 15 (filled-in by user) elements in the new page. Using mwfields you can tell _create specifically what form element to use to create a new page. So, when creating multiple new pages with one form, mwfields should be used with any and all _create. See example 3.
- Create a new page and fill different content slots for that page. You have to give the definition of the first _create an id. The other _create elements reference the first _create with a mwwrite like mwwrite="::id::<idOfWSCreateWithID>". See example 4.
Example 1 : Create a new page with the next available number
<_create mwwrite="orders/" mwtemplate="Order" mwoption="next_available" />
Create a new page with the next available number in a range and always start from the beginning
<_create mwwrite="orders/" mwtemplate="Order" mwoption="range:2019000:2019999" />
<_create mwwrite="Proj-solution:" mwoption="add_random" mwtemplate="Solution" />
Example 2 : Create from text, mwrandom and fieldvalues
<_create mwwrite="Proj-solution:[namefield]/[mwrandom]" mwtemplate="Solution" />
Example 3 : Create from text and field values and only include specific form element names in the new template
<_create mwwrite="Proj-solution:[namefield]/Personal" mwtemplate="Personal" mwfields="naam, adres, straat, plaats" /> <_create mwwrite="Proj-solution:[namefield]/Business" mwtemplate="Business" mwfields="Company, cadres, cstraat, cplaats" />
Example 4 : Create a page with title : Test/[title]. With no main content and a template of Structured data with an argument of Hello in slot:mds-metadataslot". At the same time content slot "mds-metadataslot2" get the same template with argument Hello2.
<_create id="testingSlot" mwwrite="Test/[title]" mwtemplate="Structured data" mwfollow mwfields="Hello" mwslot="mds-metadataslot" /> <_create mwwrite="::id::testingSlot" mwtemplate="wsnone" mwfields="Hello2" mwslot="mds-metadataslot2" />
If you create a page from text, mwrandom and field values and also add mwoption="add_random", another random number will be added to the end of the page title.
You can have multiple instances of _create in a form, as long as mwfields is an argument with every _create. If you have multiple _create and they all have a mwfollow, the last _create in the list will be followed.