silverstripe-nocaptcha icon indicating copy to clipboard operation
silverstripe-nocaptcha copied to clipboard

Bootsrap Form

Open lestercomia opened this issue 8 years ago • 3 comments

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"

`

lestercomia avatar Nov 22 '17 21:11 lestercomia

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 avatar Nov 22 '17 21:11 UndefinedOffset

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.

UndefinedOffset avatar Nov 22 '17 21:11 UndefinedOffset

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.

a2nt avatar Dec 10 '18 13:12 a2nt