1

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.

<?
$params="";

foreach($_POST as $name=>$value)
{
    if ($name!="controllerPage")
    {
        $params=$params.$name."=".$value."&";
    }
}
?>

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

<? echo $params; ?> 

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

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

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

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 %}

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

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 %}
| improve this answer | |
  • for some reason it doesn't recognise the name variable. I solved the issue in a more complex way ;-) – Robbie Post Dec 7 '16 at 9:55
  • By changing craft.request.getSegments() to craft.request.getPost() I was able to get it working. Thanks! – Robbie Post Dec 7 '16 at 10:04
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

| improve this answer | |
  • Getting a Array to string conversion error using the above. – Robbie Post Dec 6 '16 at 7:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.