I want to add some templating options to validationErrorBulkTpl
At the moment formit can only output something like this:
with the following result:
<li>name: You have to insert a valid email Adress</li>
What I want to use is:
<li>
<span class="field">[[+field:ucase]]</span>
<span class="message">[[+error]]</span>
<sup><a href="[[~[[*id]]]][[+field]]" title="go to error">(*)</a></sup>
</li>
Which should result in
<li>
<span class="field">Name:</span>
<span class="message">You have to insert a valid email Adress</span>
<sup><a href="example.com/contactform.html#email" title="go to error">(*)</a></sup>
</li>
Note: In this example I can use a :ucase output filter as well as position the fieldname anywhere.
validationErrorBulkTpl is mostly processed inside a foreach loop starting at line 688 in core/components/formit/model/formit/fivalidator.class.php.
$err = $field.': '.$err;
$errs[] = str_replace('[[+error]]',$err,$this->config['validationErrorBulkTpl']);
See source here:
https://github.com/splittingred/FormIt/blob/develop/core/components/formit/model/formit/fivalidator.class.php#L685
As an alternative I wrote the following lines:
foreach ($this->getRawErrors() as $field => $err) {
$this->modx->setPlaceholder('field',$field);
$this->modx->setPlaceholder('error',$err);
/* Inline option: NO SUPPORT for output filters? */
if ( substr($validationErrorBulkTpl, 0, 6) == "@CODE:" )
{
/* Create temp chunk */
$tpl = substr($validationErrorBulkTpl, 6);
$chunk = $this->modx->newObject('modChunk');
$chunk->setCacheable(false);
$chunk->setContent($tpl);
$errs[] = $chunk->process();
}
/* External chunk: SUPPORT for output filters! */
elseif ( $this->modx->getObject( 'modChunk', array('name' => $validationErrorBulkTpl) != null) )
{
$errs[] = $this->modx->getChunk($validationErrorBulkTpl);
}
/* legacy option. No support for outputfilters but support fpr pseudo placeholders */
else
{
$haystack = $this->config['validationErrorBulkTpl'];
$search = array('[[+field]]','[[+error]]');
$replace = array($field,$err);
$errs[] = str_replace( $search , $replace , $haystack );
}
}
So far using an external chunk as a tpl seems to work.
But the internal chunk option only works halfway. I can use
[[+field]] as well as [[+error]]
but output filters are not only completely ignored, but also prevent output of a placeholder.
I'm missing something important, but I have no idea what that might be.
Please shed some light on this issue.
Regards,
pepebe
[ed. note: pepebe last edited this post 11 years, 10 months ago.]