Is there anyway to pass parameter from snippet to chunk

5.8k views Asked by At

I am learning modx and stuck at a point. I want to post "uid" value to next page via POST only and want to set hidden field which will contain "uid" as a value. I believe practically its not allowed to pass values to chunk. I want to know whats the proper way so i can get POST data and use that value in chunk ??

My procedure

1) I have created resource (document) which contains call to snippet and then chunk

2) snippet contains value retrieved from POST

3) chunk contains a form and fields, I want to inject that POST value in this form.

1

There are 1 answers

1
okyanet On BEST ANSWER

There are several ways you could do this.

1) Return the uid value directly from the snippet (let's call it getPostData), and place the snippet call in your hidden field in the chunk like this:

<input type="hidden" name="uid" value="[[!getPostData]]" />

Note the snippet is uncached ([[! opening tag) otherwise the first form submission will be cached.

2) Place the snippet call in the chunk tag and have the value passed into a placeholder:

[[$myChunk?uid=`[[!getPostData]]`]]

...and in your chunk set an uncached placeholder for 'uid':

<input type="hidden" name="uid" value="[[!+uid]]" />

3) Recommended: Use setPlaceholders() in your snippet to output content to placeholders anywhere in your page - you can use it to output to multiple placeholders:

<?php
// please sanitise your POST values, this is just an example
$placeholders = array();
$placeholders['uid'] = $_POST['uid'];
$placeholders['email'] = $_POST['email'];

$modx->setPlaceholders($placeholders);

...and your chunk:

<input type="hidden" name="uid" value="[[!+uid]]" />
<input type="email" name="email" value="[[!+email]]" />

Documentation: http://rtfm.modx.com/display/revolution20/modX.setPlaceholders