Quote from: lkfranklin at Aug 09, 2017, 07:17 PMThat should actually work. Can you post your call?
This is my Form:
[[!FormIt? &validate= `kennwort:required,
text:required:stripTags,
startWarn:regexp=^/[0-9]{2}[\/][0-9]{4}[zZ]/^,
endWarn:regexp=^/[0-9]{2}[\/][0-9]{4}[zZ]/^,
issued:regexp=^/[0-9]{2}[\/][0-9]{4}[zZ]/^,
lfdNr:regexp=^/[0-9]{2}/^`
&clearFieldsOnSuccess= `0`
&preHooks= `loadWarnformParam`
&hooks= `warnForm`
]]
[[!+fi.validation_error_message:notempty=`<p>[[!+fi.validation_error_message]]</p>`]]
<form action="[[~[[*id]]]]" method="post" class="form">
<section>
<fieldset>
<legend>Inhalt:</legend>
<div>
<label for="kennwort"> Kennwort: <span class="error">[[!+fi.error.kennwort]]</span></label>
<input type="text" name="kennwort" id="kennwort" placeholder="Gewitter, Wind, Starkniederschlag etc." value="[[!+fi.kennwort]]">
</div>
<div id="warntext>
<label for="text"> Warntext: <span class="error">[[!+fi.error.text]]</span></label>
<textarea name="text" id="text" cols="50" rows="3" placeholder="Bitte Warntext eingeben..." value="[[!+fi.text]]" />[[fi.text]]</textarea>
</div>
<div>
<label for="startWarn"> gültig von: <span class="error">[[!+fi.error.startWarn]]</span></label>
<input type="text" name="startWarn" id="startWarn" placeholder="15/0800Z" value="[[!+fi.startWarn]]">
</div>
<div>
<label for="endWarn"> bis: <span class="error">[[!+fi.error.endWarn]]</span></label>
<input type="text" name="endWarn" id="endWarn" placeholder="15/2200Z" value="[[!+fi.endWarn]]">
</div>
<div>
<label for="issued"> herausgegeben am: <span class="error">[[!+fi.error.endWarn]]</span></label>
<input type="text" name="issued" id="issued" value="[[!+fi.issued]]">
</div>
<div>
<label for="lfdNr"> ETMN Nr: <span class="error">[[!+fi.error.lfdNr]]</span></label>
<input type="text" name="lfdNr" id="lfdNr" placeholder="01" value="[[!+fi.lfdNr]]">
</div>
<div>
<label for="chngcncl"> Aufhebung/Änderung: <span class="error">[[!+fi.error.chngcncl]]</span></label>
<input type="text" name="chngcncl" id="chngcncl" placeholder="Aufhebung Nr.XX/Änderung Nr. XX" value="[[!+fi.chngcncl]]">
</div>
</fieldset>
<div class="form-buttons">
<input type="submit" value="Warnung erstellen">
</div>
</section>
</form>
this is the prehook
<?php
$fp = fopen("images/geomops1/Warnung_nicht_loeschen.txt","r");
$i = 0;
if($fp){
while(!feof($fp)){
$zeile[$i] = fgets($fp);
$i++;
}
fclose($fp);
$hook->setValue('kennwort', substr($zeile[0],3));
$hook->setValue('text', substr($zeile[1], 3));
$hook->setValue('startWarn', substr($zeile[2], 15, 8));
$hook->setValue('endWarn', substr($zeile[2], 28, 8));
if (strlen($zeile[4]) !== 0) {
$hook->setValue('issued', substr($zeile[4], 14, 8));
} else {
$timestamp = time();
$datum = date("d/Hi", $timestamp) . "Z";
$hook->setValue('issued',$datum);
}
$hook->setValue('lfdNr', substr($zeile[5], 12, 2));
}
else {
$modx->log(xPDO::LOG_LEVEL_ERROR,'unable to open $Bulletin');
print "Datei $Bulletin nicht gefunden<br>";
$timestamp = time();
$datum = date("d/Hi", $timestamp) . "Z";
$hook->setValue('issued',$datum);
}
return true;
and this is the hook processing the form and writing the *txt file
<?php
$hook=$scriptProperties['hook'];
$kennwort = $hook->getValue('kennwort');
$warntext = $hook->getValue('text');
$startWarn = $hook->getValue('startWarn');
if (stristr($startWarn, "Z") === FALSE) {
$startWarn = $startWarn . "Z";
}
$endWarn = $hook->getValue('endWarn');
if (stristr($endWarn, "Z") === FALSE) {
$endWarn = $endWarn . "Z";
}
$issued = $hook->getValue('issued');
if (stristr($issued, "Z") === FALSE) {
$issued = $issued . "Z";
}
$lfdNr = $hook->getValue('lfdNr');
$chngcncl = $hook->getValue('chngcncl');
if (strlen($chngcncl) > 0) {
$chngcncl = "\r\n" . "7. " . $chngcncl;
} else {
$chngcncl = "";
}
$sign = $hook->getValue('sign');
$check = "cancel";
if (strcasecmp($warntext, "cancel") !== 0) {
$text = "1. " . $kennwort . "\r\n" . "2. " . $warntext . "\r\n" . "3. Gültig von " . $startWarn . " bis " . $endWarn . "\r\n" . "4. ETMN und Umgebung " . "\r\n" . "5. ausgegeben " . $issued . "\r\n" . "6. ETMN Nr. " . $lfdNr . $chngcncl;
} else {
$text="";
}
$myfile = fopen("images/geomops1/Warnung_nicht_loeschen.txt", "w") or $modx->log(xPDO::LOG_LEVEL_ERROR, 'unable to write warn message');
fwrite($myfile, $text);
fclose($myfile);
return true; //<-- if you omit this or return false, your form won't validate
Hope this helps
Sincerely Thomas