UndefinedOffset / silverstripe-nocaptcha

A spam protector and form field using Google's reCAPTCHA v2 or optionally a foundation v3 implementation
BSD 3-Clause "New" or "Revised" License
31 stars 37 forks source link

Bootsrap Form #38

Open lestercomia opened 6 years ago

lestercomia commented 6 years ago

When using a bootstrap form module and using norecaptcha. Validation Error wont show up.

see nocaptcha/lang/en.yml

` en: NocaptchaField:

    EMPTY: "Please answer the captcha, if you do not see the captcha please enable JavaScript"

    NOSCRIPT: "You must enable JavaScript to submit this form"

    VALIDATE_ERROR: "Captcha could not be validated"

`

UndefinedOffset commented 6 years ago

What version of SilverStripe are you using? If you are using SilverStripe 4 make sure you are using the latest from master or 2.0.0-alpha2. If you are using SilverStripe 3 make sure you are using 1.0.0 or the latest from 1.0.x.

Also is the error message simply blank? It's also possible if bootstrap is intercepting the submission process for the form you may need to trigger the recaptcha api manually.

UndefinedOffset commented 6 years ago

Also note the validation error message will only show after submission to the server as validation is done server side. It will not show up prior to that.

a2nt commented 5 years ago

Guess this note will be helpful.

If u have custom validator class u will need to check every field manually, ex:

class MyCustomValidator extends Validator {
   public function php($data)
   {
       $valid = true;
        $fields = $this->Form()->Fields();
        foreach($fields as $field) {
           $valid = $valid && $field->validate();
         }
         // your custom validation
         return $valid;
   }
}

but if u will extend SilverStripe\Forms\RequiredFields it will work ok:

class MyCustomValidator extends RequiredFields {
   public function php($data)
   {
        $valid = parent::php($data);
        // your custom code
        return $valid;
   }
}

bootstrap form module + norecaptcha works ok without custom validation.