We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28042 ☆ A M B ☆
    • 24,524 Posts
    It just occurred to me that there should be a way to specify a validation string in the eform attribute for a "dummy" field that must be left empty to trap bots. As it is, I’m using a snippet/function to do this, but I suspect that it’s not necessary. I’ve never used the custom validation section; can somebody help me out with this idea?
      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
      • 5340
      • 1,624 Posts
      Hi Susan

      Here’s something from the back of my head. Not tested but it should work

      html
      <input name="spam" value="" type="text"/>


      +

      calls

      [!checkFields!]
      [!eForm? ....  &eFormOnValidate=`checkFields`   .....!]


      +

      snippet checkFields

      function checkFields(&$fields, &$vMsg, &$rMsg) {
      	if($fields['spam'] != ''){
      		$rMsg['spam'] = "You're a spammer!";
      		return false;
      	}
      	return true;
      }

        • 5340
        • 1,624 Posts
        It just came to me that there might be another solution using the REGEX validation rule ( not tested )

        <input value="" name="spam" type="text" eform="Spam:::You're a spammer!:#REGEX /^$/">


        /^$/ - should match anything that is not empty()

        Good luck
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          That’s more what I had in mind. I already have a snippet with a function that simply silently aborts eForm (actually named checkField, by the way)
          <?php
          function checkField(&$fields,&$vMsg,&$rMsg) {
              if(!empty($fields['fieldname'])) {
                  return false;
              } else {
              return true;
              }
          }
          ?>

          It just seems to me that an inline validation rule should do the trick without the extra snippet and function.
            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