Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

JhumanJ/OpnForm

3005 stars
2 code files
View JhumanJ/OpnForm on GitHub

app/Rules/ValidHCaptcha.php

Open in GitHub
use Illuminate\Contracts\Validation\ImplicitRule;
use Illuminate\Support\Facades\Http;
 
class ValidHCaptcha implements ImplicitRule
{
const H_CAPTCHA_VERIFY_URL = "https://hcaptcha.com/siteverify";
 
private $error = 'Invalid CAPTCHA. Please prove you\'re not a bot.';
 
public function passes($attribute, $value)
{
if (empty($value)) {
$this->error = "Please complete the captcha.";
return false;
}
 
return Http::asForm()->post(self::H_CAPTCHA_VERIFY_URL, [
'secret' => config('services.h_captcha.secret_key'),
'response' => $value
])->json('success');
}
 
public function message()
{
return $this->error;
}
}

app/Http/Requests/AnswerFormRequest.php

Open in GitHub
use App\Models\Forms\Form;
 
use App\Rules\StorageFile;
use App\Service\Forms\FormLogicPropertyResolver;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Str;
use Illuminate\Validation\Rule;
use Illuminate\Http\Request;
use App\Rules\ValidHCaptcha;
 
class AnswerFormRequest extends FormRequest
{
//
public function rules()
{
//
 
// Validate hCaptcha
if ($this->form->is_pro && $this->form->use_captcha) {
$this->requestRules['h-captcha-response'] = [new ValidHCaptcha()];
}
return $this->requestRules;
}
//
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.