[[!FormIt? &hooks=`saveChronicleProcessor,redirect` &redirectTo=`15` &redirectParams=`{"id":"[[!+grow.id]]"}` // <------ The placeholder isn't setting the parameter, it stays blank. &validate=` day:required:isNumber, week:required:isNumber, summary:required:minLength=^50^, content:required, publish_on:isDate,` ]] [[!+grow.id]] // <----- This line here is being output as expected.
This question has been answered by Bruno17. See the first response.
[[setId]] <hr> <h2>Testing stuff...</h2> [[!FormIt? &hooks=`redirect` &redirectTo=`4` &redirectParams=`{"id":"[[+setId]]"}` ]] <form action="[[~[[*id]]]]" method="post"> <input type="text" name="name"> <input type="submit" name="submit" value="Submit"> </form>
<?php $modx->toPlaceholder('setId', '123'); return;
I just tested this - note that the setId snippet is above the FormIt snippet - and it works as expected:
[[setId]] <hr> <h2>Testing stuff...</h2> [[!FormIt? &hooks=`redirect` &redirectTo=`4` &redirectParams=`{"id":"[[+setId]]"}` ]] <form action="[[~[[*id]]]]" method="post"> <input type="text" name="name"> <input type="submit" name="submit" value="Submit"> </form>
And the setId snippet
<!--?php $modx--->toPlaceholder('setId', '123'); return;
Worked as expected.
Make sure you have the snippet that sets the grow.id placeholder above the placeholders on the page.
Try making the placeholder tags cached. Having them uncached can delay their processing and they may not have been processed by the time the FormIt tag is parsed. If that doesn't work, try changing the grow.id placeholder into a snippet tag and have a snippet return the value you want there.
[[!setId]] <hr> <h2>Testing stuff...</h2> [[!FormIt? &hooks=`redirect` &redirectTo=`4` &redirectParams=`{"id":"[[!+grow.id]]"}` ]] <form action="[[~[[*id]]]]" method="post"> <input type="text" name="name"> <input type="submit" name="submit" value="Submit"> </form>
$redirectParams = array(); $redirectParams['id'] = getYourIDHere(); $scriptProperties['redirectParams'] = $modx->toJson($redirectParams); return $modx->runSnippet('FormIt',$scriptProperties);
[[!setRedirectParamsAndRunFormit? &hooks=`redirect` &redirectTo=`4` &redirectParams=`{"id":"[[!+grow.id]]"}` ]]
[[!saveChroniclePreProcessor]] [[!FormIt? &hooks=`saveChronicleProcessor,redirect` &redirectTo=`15` &redirectParams=`{"id":"[[+grow.id]]"}` &validate=`day:required:isNumber, week:required:isNumber, summary:required:minLength=^50^, content:required:allowTags, publish_on:optional:isDate, leader_url:required` ]] [[+grow.id]]
that you see the processed placeholder of [[+grow_id]] in your form, doesn't mean, it is allready processed at the time, when Formit is running.
What is the code of 'saveChroniclePreProcessor'
<?php $prefix = 'xyz_'; $packagename = 'moarDataStuff'; $classname = 'Chronicles'; $packagepath = $modx->getOption($packagename . '.core_path', NULL, $modx->getOption('core_path') . 'components/' . $packagename . '/'); $modelpath = $packagepath . 'model/'; $modx->addPackage( $packagename, $modelpath, $prefix); $chronicle = $modx->getObject( $classname, array( 'chronicle_id' => $_GET['id'] )); if (!is_object($chronicle) || !($chronicle instanceof xPDOObject)) { $errorMsg = 'saveChroniclePreProcessor -> Failed to create object of type: ' . $classname; $modx->log(modX::LOG_LEVEL_ERROR, $errorMsg, '', 'chronicleThis Dashboard'); return; } if ( $chronicle->get('grower_id') === $_SESSION['uid'] ) { $placeholders['dashboard.subtitle'] = ': '.$chronicle->get('title'); $placeholders['chronicle.id.field'] = '<input type="hidden" name="chronicle_id" id="chronicle_id" value="'.$_GET['id'].'" />'; $placeholders['grow.id.field'] = '<input type="hidden" name="grow_id" id="grow_id" value="'.$_GET['gid'].'" />'; $placeholders['fi.leader'] = $chronicle->get('leader_url'); if ( $chronicle->get('day') ) { $placeholders['fi.day'] = $chronicle->get('day'); } if ( $chronicle->get('week') ) { $placeholders['fi.week'] = $chronicle->get('week'); } $placeholders['fi.summary'] = $chronicle->get('summary'); $placeholders['fi.content'] = $chronicle->get('content'); $placeholders['fi.tags'] = $chronicle->get('tags'); $placeholders['grow.id'] = $_GET['gid']; $placeholders['formit.call'] = '[[!FormIt?'. '&hooks=`saveChronicleProcessor,redirect`'. '&redirectTo=`15`'. '&redirectParams=`{"id":"'.$_GET['gid'].'"}`'. '&validate=`day:required:isNumber,'. 'week:required:isNumber,'. 'summary:required:minLength=^50^,'. 'content:required,'. 'publish_on:isDate`'. ']]'; $var = $chronicle->get('publish_on'); $date = date('m/d/Y', strtotime($var)); $placeholders['fi.publish.date'] = $date; if ( $chronicle->get('published') === 1 ) { $placeholders['fi.published'] = 'checked'; } else { $placeholders['fi.published'] = ''; } } else { $url = $modx->makeUrl( 7 ); $modx->sendRedirect( $url ); } $modx->setPlaceholders( $placeholders );