-
- 409 Posts
Hi,
I'm looking for a way to validate the form only if at least "email" OR "phone number" fields is filled.
If the both fields are filled, the form can validate.
Is it possible to make this with FormIt ?
-
- 3,975 Posts
I think you can write custom post-hook. Check $_POST and analyze, check if one of them is filled, then keep processing or throw an error.
-
- 5,888 Posts
you can also wrap FormIt inside a custom-snippet and build the validation-property on-the-fly:
<?php
$validations = array();
$validations['name'] = 'required';
$validations['email'] = 'required:email';
$validations['phone'] = 'required:isnumber';
$email = $modx->getOption('email',$_REQUEST);
$phone = $modx->getOption('phone',$_REQUEST);
//we need only one of email or phone
if (!empty($email)){
unset($validations['phone']);
}
if (!empty($phone)){
unset($validations['email']);
}
$validate = array();
foreach ($validatons as $field=>$validation){
$validate[] = $field . ':' . $validation;
}
$scriptProperties['validate'] = implode(',',$validate);
return $modx->runSnippet('FormIt',$scriptProperties);