We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28173
    • 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 ?
      • 33337
      • 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.
        Zaigham R - MODX Professional | Skype | Email | Twitter

        Digging the interwebs for #MODX gems and bringing it to you. modx.link
        • 28042 ☆ A M B ☆
        • 24,524 Posts
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
          • 4172
          • 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);
          
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!