Submit Content Form - Documentation topics on: deprecated,macros,submit content,.

Submit Content Form
Deprecated

** This macro has been deprecated. It is recommended that front end forms that submit content should use the content API. See the following documentation links which include sample forms: **
Content API
Save Content using REST API
Content API - POST
Content API - JSONP & Binary Submit
Content API - JSONP

This macro creates a Front-end content submission form after being passed a Content Type. *User/role permissions on the Content Type are respected to establish the right to contribute content (See Form Permissions). This macro should be utilized to add NEW content via a Front-end form. To edit EXISTING content via a Front-end form, webmasters should utilize the #submitContentEdit macro.

*The "CMS Anonymous" role can be added with Edit permissions on the Content Type to allow "anonymous" Front-end content contribution.

Optionally, this macro can be used with captcha validation, create of a work flow task to a particular role moderator, and be set to automatically publish content, if desired. These and other settings are listed under "Options" below.

Custom Field Handling

Custom fields are supported by the #submitContent and #submitContentEdit macros. Some javascript handling is required to display values in custom fields on the Front-end form. The sample code below, for example, can be placed in a custom code field named "source", which allows the Front-end content contributor to choose a host from a multi-select list that is dynamically created from existing hosts in the system:

##Multiselect for hosts where news and events will be pulled from
<select multiple size="10" id="msSource" name="msSource">
  #set($siteList = $dotcontent.pull('+contentType:Host
+live:true +deleted:false',0,'Host.hostName'))
   #foreach ($site in $siteList)
         <option value="$!{site.identifier}"
#if($listTool.contains($source.split(',') ,
"$site.identifier"))selected="selected" #end
>$!{site.hostName}   
</option>
   #end
</select>
<script type="text/javascript">
  function updateSource() {
    var sourceHosts = '';
      var hselect = document.getElementById("msSource");
      for(var i = 0; i    
< hselect.options.length; i++) {
          if(hselect.options[i].selected) {
              sourceHosts = sourceHosts + ',' + hselect.options[i].value;
          }
      }
      document.getElementById("source").value = sourceHosts;
  }
  // Connect the onChange to the select
  dojo.connect(dojo.byId("msSource"), "onchange", null, "updateSource");
</script>
Handling Required Relationships

If the content being submitted has a required relationship condition, the Webmaster should set the $relationship_name variable (before calling the submitContent macro), with the identifier of the other contentlet that should be related to the content being contributed.

Setting Default Field Values

The default value of a particular field can be set - $default<fieldVelocityName> - for any field (if applicable), before calling the submitContentEdit macro. ***Special Note***, the first letter of the velocity variable name needs to be capitalized regardless of how it appears on the Content Type. So if the variable name of the field is "answer" then the example below is how you would set a default value by capitalizing the first letter of the velocity variable name:

Ex: #set($defaultAnswer="yes")
Macro Overview:

Syntax:

#submitContent('Content Type name')

Arguments:

  • Content Type name
    This is the case-sensitive name of the Content Type that will be used to generate the Front-end content submission form and form fields. The velocity variable name of the Content Type may also be used.

Optional Parameters:

  • contentFormReferer (velocity variable- not a parameter)
    Optional: redirects the user to the specified relative path after form submission. For example: '/forms/thankyoupage.dot'
    Default: If this variable is not set, then after form submission, the submitContent macro form returns the Front-end user to the same form page by default with "content saved" messaging inserted at the top of the form.
  • contentAutoPublish (velocity variable- not a parameter)
    Optional: If set to true, the new content submitted will automatically published upon save.
    Default: false
  • contentUseCaptcha (velocity variable not a parameter)
    Optional: If set to "true", the form will display a captcha image to the submit content form, to validate human interaction
    Default: false
  • contentUseAudioCaptcha (velocity variable- not a parameter)
    Optional: If set to "true" shows an audio captcha on the content form, to validate human interaction
    Default: false
  • contentUseAudioCaptchaHeight (velocity variable not a parameter)
    Optional: If 'contentUseAudioCaptcha' var is set to "true", the height of the audio player used will be:
    Default: 30
  • contentModeration (velocity variable- not a parameter)
    Optional: If set, that will be the ROLE KEY of the role to assign the workflow
  • showOnlyRequiredFields (velocity variable- not a parameter)
    Optional: If set to "true" shows only the required fields from the contentlet being submitted
    Default: false
  • dontShowFields (velocity variable- not a parameter)
    Optional: If set, the comma separated list of velocity variable names set cause the corresponding content fields to be hidden from the submit content form. For example:
    #set($dontShowFields= "description, photo")
  • default<velocity field name> (velocity variable not a parameter)
    If the Webmaster wants to use a different default value for a particular field, could add a default variable
    For example, to change the default value for a field called "Summary" on the Content Type, the variable could be:
    #set($defaultSummary= "Test Summary")
  • <relationship_name> (velocity variable not a parameter)
    If the Content Type has a required relationship, the Webmaster must set an array variable with the relationship name and the identifier(s) of the corresponding contentlet(s) that should be related to the submitted contentlet upon save.
    For example: if a required relationship between News and Comments Content Types exists, the Webmaster should add a variable like this
       #set($News_Comments= ["12345","67890"])
    The values in the comma separated list must be the identifiers of the contentlets to be related to the content being submitted in the Front-end form. If any of the content identifiers are invalid, the relationship(s) will not be saved. Non-required relationships may also be set in the same way.
  • dateCalendarCSS (velocity variable- not a parameter)
    Optional: This variable can be used to set the custom style sheet for the calendar popup provided by date fields.
  • contentFormMacroCSS (velocity variable- not a parameter)
    Optional: This variable can be used to set the custom style sheet to over-ride the default dojo classes being used on all form fields.
  • errorMessagesPath (velocity variable- not a parameter)
    Optional: Sets the path to a custom page that will display the error/success message handling for the form. The default page is set to static/messages.html.

Usage:

Use this macro to submit a new piece of content from a Front-end form.
Examples:

Example 1: A simple example using the required fields

This code example creates a news content contribution form and forwards user to the news index page after submit.

#set($contentFormReferer = "/news/index.dot")

#submitContent("News")

Example 2: An example using more of the optional parameters

 submitContent macro with image captcha validation, a workflow task, modify the default value for the title field, and relating two comment contentlets on a required relationship to the News Content Type.

#set($contentUseCaptcha = true)

#set($contentModeration= "reportuser")

#set($defaultTitle = "TEST TITLE")

#set($News-Comments = ["321229","321231"])

#submitContent("News")  

Example 3: An example showing how to include additional parameters

This example creates a submit content form with: audio captcha validation, content auto publish, showing only the required fields, hiding the info, test and photo fields, and modifying the default description field value.

#set($contentUseCaptcha = true)

#set($contentUseAudioCaptcha = true)

#set($contentAutoPublish = true)

#set($showOnlyRequiredFields = true)

#set($dontShowFields = "info, test, photo")

#set($defaultDescription = "TEST Description")

#submitContent("News")