Encouraged by Susans idea I have spent almost a full day experimenting. Unfortunately with no success at all.
I use &eformOnValidate to call my own validation function. I include it as a snippet like the docs suggested. I use modx system event logging to check if my validation runs. In reports > system events I can see it all runs as expected.
If I load the page I see my form and the debug info. After submit nothing shows up, regardless of my return value. If i remove my &eformOnValidate parameter from the call it works again.
I’d appreciate some help. At this point I completely ran out of ideas and I wonder whether it is possible at all.
my form chunk "eFormSignup"
<span style="color: crimson">
[+validationmessage+]
</span>
<form action="[(base_url)][~[*id*]~]" method="post">
<input type="hidden" name="formid" value="eFormSignup" />
<fieldset>
<legend>Registrieren</legend>
<p>
<label>Email</label>
<input class="field" type="text" name="email1" size="40" maxlength="40" />
</p>
<p>
<label>Repeat Email</label>
<input class="field" type="text" name="email2" size="40" maxlength="40" />
</p>
<p>
<label>Password</label>
<input class="field" type="text" name="pass1" size="40" maxlength="40" />
</p>
<p>
<label>Repeat Password</label>
<input class="field" type="text" name="pass2" size="40" maxlength="40" />
</p>
<p>
<input type="submit" name="submit" value="OK" />
</p>
</fieldset>
</form>
My snippet ’validateFunctions’
<?php
function validPass($pass)
{
global $modx;
$modx->logEvent(998, 1, 'start validPass', 'validPass');
if (strlen($pass) < 5)
{
$modx->logEvent(998, 1, 'pass too short', 'validPass');
return false;
}
$modx->logEvent(998, 1, 'pass long enough', 'validPass');
return true;
}
function validEmail($email)
{
global $modx;
$modx->logEvent(998, 1, 'start validEmail', 'validEmail');
if (strlen($email) < 3)
{
$modx->logEvent(998, 1, 'email invalid', 'validPass');
return false;
}
return true;
}
function checkSignup(&$fields, &$vMsg, &$rMsg)
{
global $modx;
$modx->logEvent(998, 1, 'start checkSignup', 'checkSignup');
$errors = 0;
// check password fields
if ($fields['pass1'] !== $fields['pass2'])
{
$modx->logEvent(998, 1, 'passwords dont match', 'checkSignup');
$pass = $formpass;
$vMsg['pass1'] = "Passwords dont match";
$errors++;
}
else
{
if (!validPass($fields['pass1']))
{
$modx->logEvent(998, 1, 'password rule fail', 'checkSignup');
$vMsg['pass1'] = "Password needs to be at least 5 characters long";
$errors++;
}
}
// check email fields
if ($fields['email1'] !== $fields['email2'])
{
$modx->logEvent(998, 1, 'email2 dont match', 'checkSignup');
$pass = $formpass;
$vMsg['email1'] = "Email Adresses dont match";
$errors++;
}
else
{
if (!validEmail($fields['email1']))
{
$modx->logEvent(998, 1, 'email rule fail', 'checkSignup');
$vMsg['email1'] = "Email Adresse is invalid";
$errors++;
}
}
if ($errors > 0)
{
$modx->logEvent(998, 1, 'errors found, returning false', 'checkSignup');
return false;
}
$modx->logEvent(998, 1, 'no errors found, returning true', 'checkSignup');
return true;
}
function doSignup(&$fields)
{
global $modx;
$modx->logEvent(998, 1, 'start doSignup', 'doSignup');
$modx->logEvent(998, 1, 'dummy function returning true', 'doSignup');
return true;
}
//return empty string
return '';
?>
My chunk ’eFormSignupThanks’
<p>Thanks for signing up for our website.</p>
My chunk ’eFormSignupReport’
<p>A new user has signed up</p>
<table>
<tr valign="top"><td>Email:</td><td>[+email1+]</td></tr>
</table>
My snippet calls on the page
[!validateFunctions!]
[!eForm? &formid=`eFormSignup` &to=`[email protected]` &tpl=`eFormSignup` &report=`eFormSignupReport` &thankyou=`eFormSignupThanks` &subject=`mydomain.com - A new User just signed up` &protectSubmit=`0` &eformOnValidate=`checkSignup` &debug=`1`!]