<p>100% untested, but something like this should work:</p>

<pre><code>{% set segments = craft.request.getPost() %}
{% set stringParams = '' %}

{% for name, segment in segments %}
    {% if name not 'controllerPage' %}
        {% set stringParams = stringParams ~ name ~ '=' ~ segment ~ '&amp;'
    {% endif %}
{% endfor %}
</code></pre>

CC BY-SA 3.0
2016-12-07T09:55:40.300Z
for some reason it doesn't recognise the name variable. I solved the issue in a more complex way ;-)
Robbie Post
CC BY-SA 3.0
2016-12-07T10:04:06.900Z
By changing craft.request.getSegments() to craft.request.getPost() I was able to get it working. Thanks!
Robbie Post
CC BY-SA 3.0
2016-12-06T21:52:11.540Z
2016-12-07T17:23:30.270Z
2016-12-07T17:23:30.270Z
Brad Bell
<p>I think you can do this in the template by using for example:</p>

<pre><code>craft.request.getSegments
</code></pre>

<p>or</p>

<pre><code>craft.request.getParam( name )
</code></pre>

<p>See the docs:</p>

<p><a href="https://craftcms.com/docs/templating/craft.request" rel="nofollow noreferrer">https://craftcms.com/docs/templating/craft.request</a></p>

CC BY-SA 3.0
2016-12-06T07:50:47.070Z
Getting a Array to string conversion error using the above.
Robbie Post
CC BY-SA 3.0
2016-12-05T17:04:14.817Z
2016-12-05T17:04:14.817Z
Floriskoch
<p>I'm not a plugin developer, nor is my knowledge of PHP sufficient to handle this issue.</p>

<p>I need a simple method or plugin, to be able to generate this PHP code in a template.</p>

<pre><code>&lt;?
$params="";

foreach($_POST as $name=&gt;$value)
{
    if ($name!="controllerPage")
    {
        $params=$params.$name."=".$value."&amp;";
    }
}
?&gt;
</code></pre>

<p>In the same template I need this code to retrieve the above</p>

<pre><code>&lt;? echo $params; ?&gt; 
</code></pre>

<p>Who can show me the way?</p>

<p>This is the POST data that is attached to the URL</p>

<pre><code>$_POST=array (
'view' =&gt; 'SearchResult',
'controllerPage' =&gt; 'https://navigantes.eu/yachts-search',
'customCssPath' =&gt; 'https://navigantes.eu/css/booking-manager-small.css',
'setlang' =&gt; 'en',
'target' =&gt; '_blank',
'companyid' =&gt; '1234',
'filter_country' =&gt; 'HR',
'filter_region' =&gt; '',
'filter_base' =&gt; '',
'filter_year' =&gt; '2016',
'filter_month' =&gt; '11',
'filter_date' =&gt; '10',
'filter_duration' =&gt; '7',
'filter_flexibility' =&gt; 'on_day',
)
</code></pre>

<p>Which needs to be translated to this:</p>

<pre><code>view=SearchResult&amp;amp;customCssPath=https://navigantes.eu/css/booking-manager-small.css&amp;amp;setlang=en&amp;amp;target=_blank&amp;amp;companyid=1234&amp;amp;filter_country=HR&amp;amp;filter_region=&amp;amp;filter_base=&amp;amp;filter_year=2016&amp;amp;filter_month=11&amp;amp;filter_date=10&amp;amp;filter_duration=7&amp;amp;filter_flexibility=on_day&amp;
</code></pre>

<p>Solved the issue by using {{ craft.request.getPost('') }} method:</p>

<pre><code>            &lt;iframe name="" width="100%" height="800" frameborder="0" scrolling="auto"
            src="https://www.booking-manager.com/wbm2/page.html?
                view={{ craft.request.getPost( 'view' ) }}&amp;
                customCssPath={{ craft.config.environmentVariables.rootUrl }}/css/booking-manager-small.css&amp;
                setlang={{ craft.request.getPost( 'setlang' ) }}&amp;
                companyid={{ craft.request.getPost( 'companyid' ) }}&amp;
                filter_country={{ craft.request.getPost( 'filter_country' ) }}&amp;
                filter_region={{ craft.request.getPost( 'filter_region' ) }}&amp;
                filter_base={{ craft.request.getPost( 'filter_base' ) }}&amp;
                filter_year={{ craft.request.getPost( 'filter_year' ) }}&amp;
                filter_month={{ craft.request.getPost( 'filter_month' ) }}&amp;
                filter_date={{ craft.request.getPost( 'filter_date' ) }}&amp;
                filter_duration={{ craft.request.getPost( 'filter_duration' ) }}&amp;
                filter_flexibility={{ craft.request.getPost( 'filter_flexibility' ) }}&amp;
            "&gt;
        &lt;/iframe&gt;
</code></pre>

<p>And finally Brad's suggested method worked by changing craft.request.getSegments() into craft.request.getPost():</p>

<pre><code>{% set segments = craft.request.getPost() %}
{% set stringParams = '' %}

{% for name, segment in segments %}
{% if name != 'controllerPage' %}
    {% set stringParams = stringParams ~ name ~ '=' ~ segment ~ '&amp;' %}
{% endif %}
{% endfor %}

&lt;iframe name="" width="100%" height="800" frameborder="0" scrolling="auto" src="https://www.booking-manager.com/wbm2/page.html?{{ stringParams }}"&gt;
</code></pre>

<plugin-development><templating><plugins><php>
Need help with simple PHP plugin
# Need help with simple PHP plugin

(Asked by: username_0 on 2016-12-05)

I'm not a plugin developer, nor is my knowledge of PHP sufficient to handle this issue.
I need a simple method or plugin, to be able to generate this PHP code in a template.
$value)
{
    if ($name!="controllerPage")
    {
        $params=$params.$name."=".$value."&";
    }
}
?>

In the same template I need this code to retrieve the above
 

Who can show me the way?
This is the POST data that is attached to the URL
$_POST=array (
'view' => 'SearchResult',
'controllerPage' => 'https://navigantes.eu/yachts-search',
'customCssPath' => 'https://navigantes.eu/css/booking-manager-small.css',
'setlang' => 'en',
'target' => '_blank',
'companyid' => '1234',
'filter_country' => 'HR',
'filter_region' => '',
'filter_base' => '',
'filter_year' => '2016',
'filter_month' => '11',
'filter_date' => '10',
'filter_duration' => '7',
'filter_flexibility' => 'on_day',
)

Which needs to be translated to this:
view=SearchResult&customCssPath=https://navigantes.eu/css/booking-manager-small.css&setlang=en&target=_blank&companyid=1234&filter_country=HR&filter_region=&filter_base=&filter_year=2016&filter_month=11&filter_date=10&filter_duration=7&filter_flexibility=on_day&

Solved the issue by using {{ craft.request.getPost('') }} method:
            
        

And finally Brad's suggested method worked by changing craft.request.getSegments() into craft.request.getPost():
{% set segments = craft.request.getPost() %}
{% set stringParams = '' %}

{% for name, segment in segments %}
{% if name != 'controllerPage' %}
    {% set stringParams = stringParams ~ name ~ '=' ~ segment ~ '&' %}
{% endif %}
{% endfor %}

**Tags:** plugin-development, templating, plugins, php

---

## 2 answers

### Answer by username_1 on 2016-12-06. Score: 1 | Accepted answer

100% untested, but something like this should work:
{% set segments = craft.request.getPost() %}
{% set stringParams = '' %}

{% for name, segment in segments %}
    {% if name not 'controllerPage' %}
        {% set stringParams = stringParams ~ name ~ '=' ~ segment ~ '&'
    {% endif %}
{% endfor %}

> **Comments:**
> **username_0**: for some reason it doesn't recognise the name variable. I solved the issue in a more complex way ;-)  
> **username_0**: By changing craft.request.getSegments() to craft.request.getPost() I was able to get it working. Thanks!  

---

### Answer by username_2 on 2016-12-05. Score: 4

I think you can do this in the template by using for example:
craft.request.getSegments

or
craft.request.getParam( name )

See the docs:
https://craftcms.com/docs/templating/craft.request

> **Comments:**
> **username_0**: Getting a Array to string conversion error using the above.  

---

