Post Params

Post Params

{{ post_params }}

Object containing all of the HTTP posted parameters from the current request.

Name Type Description
is_valid Boolean True if there is at least one posted parameter
by_name object An object whose properties match the posted parameters from the request. If the same parameter has multiple values, they will be included as a list of strings rather than simply as a single string, and when treated as a single string the values will be comma-delimited
keys list A list containing all of the unique post parameter names
count Integer The number of unique post parameter names
length Integer The total number of post parameters, including duplicate parameters
* String Specific post parameter values may be accessed using {{ request.post_params.parametername }} or {{ request.post_params['parameter-name'] }}
output String The posted parameters formatted similar to a query parameter string (ie: as if the post request used a content-type of application/x-www-form-urlencoded)

You may treat the post_params object as a list containing all of the parameters which may be iterated using a {% for %} loop.

The post_params object is copyable using the {% copy_to_dictionary %} method.

Examples

Loop Post Parameters

Copy
<h4>Post Parameters</h4>
<dl>
{% for param in request.post_params %}
<dt>{{param}}</dt>
<dd>
{% if request.post_params.by_name[param] is_list %}
<ul>
{% for value in request.post_params.by_name[param] %}
<li>{{ value }}</li>
{% endfor %}
</ul>
{% else %}
{{ request.post_params.by_name[param] }}
{% endif %}
</dd>
{% endfor %}
</dl>

Copy Dictionary

Copy
{% create_dictionary pagination = limit:5 page:2 %}
{% create_dictionary sorting = sort_by:"post_date" sort_direction: "desc" %}

{% comment %}This will create a new dictionary if it does not already exist. Any previous filters may be overwritten from request.post_params.{% endcomment %}
{% copy_to_dictionary filters = request.post_params pagination sorting %}

{% comment %}If you use the new_only instruction then previous filters will not be overwritten.{% endcomment %}
{% create_dictionary filters = blog:entity.blog_main tag:entity.tag_filter %}
{% copy_to_dictionary filters = pagination sorting request.post_params new_only %}

Getting post parameters

Copy
{% if request.post_params.is_valid %}
{% assign var username = request.post_params['username'] %}
{% assign var password = request.post_params['password'] %}
{% if username is_valid and password is_valid %}
{% auth login username password %}
{% endif %}
{% endif %}
{% unless auth.logged_in %}
<p>Could not log in</p>
{% endunless %}