On March 26, 2019 we launched new MODX Forums. Please join us at the new MODX Community Forums.
Subscribe: RSS
  • I have a contact form based on smtp/Gmail. But there is a spam-robot sending in the name Timothywaw that I want to be blocked as sender.

    Is this possible?

    I use a Gmail-account as sender/smtp host/adresse, so all emails goes through the folder Sendt in that account. But it's not possible to make filters to the Sendt folders, so I figure I have to set in the Modx Formit setup.

    Data:
    Modx Revo 2.7.0
    Formit latest.

    Code:
    [[!FormIt?
            &hooks=`spam,email,redirect,formItAutoResponder`
            &emailTpl=`EpostmeldingTmpl`
            &emailTo=`bjorn.erik.sandbakk@gmail.com`
            &emailReplyToo=`[[+email]]`
            &emailSubject=`Melding fra kontaktskjemaet på verketyoga.no`
            &emailFromName=`[[+name]]`
            &redirectTo=`200`
            &store=`1`
            &clearFieldsOnSuccess=`1`
            &fiarTpl=`kontaktMelding-confirmation`
            &fiarFrom=`noreply.verketyoga@gmail.com`
            &fiarFromName=`noreply.verketyoga@gmail.com`
            &validate=`name:required,
              email:email:required,
              message:required:stripTags`
          ]]
          <form class="cmxform" id="contactForm" action="[[~[[*id]]]]" method="post">
            <input type="hidden" name="nospam:blank" value="[[+fi.nospam]]" />
      I think, thererfor I am! But what I am, and why...?
    • You can use FormIt &preHooks:

      [[!FormIt? &preHooks=`stopTheSpammers`]]


      and stopTheSpammers snippet code:

      $email = $hook->getValue('email'); // get email from a form that is actually sending
      $allFormFields = $hook->getValues();  // get all fields from that form to an array
      if (...) {
      ... // your filter code
      $errorMsg = 'Got ya spammer!';
      $hook->addError('user',$errorMsg);
      return false;
      } else {
      return true;
      }
      
      


      return false stops the form and return true is continuing formit script.
      https://docs.modx.com/extras/revo/formit/formit.hooks/#FormIt.Hooks-UsingpreHooks

      personally i would recommend some captcha systems i.e. google recaptcha.
      https://developers.google.com/recaptcha/docs/v3