Shazaaam!

again this is v. 1.2.1 (move to that thread if helpful)
- All errors in list context at top of form
- set default values while maintaining form state on error
What hung me up was errTpl, was expecting it to be a chunk. I mean. . . Tpl . . . yeah.
Small version of form:
<form method="post" action="[[~[[*id]]]]" id="contact-form">
<ul id="formit-errors" style="display:none;">[[$formit-errorlist]]</ul>
<p><label for="fname">First Name:</label><span class="required">*</span>
<input class="txt" type="text" id="fname" name="fname:required:stripTags" size="35" value="[[+fi.fname]]"></p>
<p><label for="emailaddr">Email Address:</label><span class="required">*</span>
<input class="txt" type="text" id="emailaddr" name="emailaddr:email:required:stripTags" size="35" value="[[+fi.emailaddr]]"></p>
<p><input type="submit" class="graphic-button" value="Submit"></p>
</form>
[[!FormIt?
&preHooks=`loadInitialValues`
&hooks=`email,redirect`
&emailSubject=`Visitor Inquiry from Your Site`
&emailTpl=`smallFormReport`
&errTpl=`<li>[[+error]]</li>`
&emailTo=`[email protected]`
&redirectTo=`123`]]
Note errTpl is a list for semantic considerations . . .
formit-errorlist
[[+fi.error.fname]]
[[+fi.error.emailaddr]]
loadInitialValues
<?php
$ph = Array(
'fi.fname' => 'Your First Name',
'fi.emailaddr' => 'Your Email Address'
);
foreach ($ph as $fld=>$def) {
$modx->setPlaceholder($fld,$def);
}
return true;
?>
At first I had it as a standalone at the top of the form as suggested, with this
foreach ($ph as $fld=>$def) {
if (! $modx->getPlaceholder($fld)) {
$modx->setPlaceholder($fld,$def);
}
}
But of course since formit hasn’t yet executed, the placeholder would always not exist at that point so it would always add the default. As a prehook it does both, adds the default fields (which is still a STUPID idea) and maintains state on error.
The only thing I DON’T like is I have the errors hidden, if innerHTML != ’’ I use JS to display them. That’s gotta go.
Now I just need to do a dynamic output for a response instead of a redirect, kinda’ liking that session idea.