Captcha.php 897 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace Dcat\Admin\Form\Field;
  3. use Dcat\Admin\Form;
  4. class Captcha extends Text
  5. {
  6. protected $rules = ['required', 'captcha'];
  7. protected $view = 'admin::form.captcha';
  8. public function __construct($column, $arguments = [])
  9. {
  10. if (!class_exists(\Mews\Captcha\Captcha::class)) {
  11. throw new \Exception('To use captcha field, please install [mews/captcha] first.');
  12. }
  13. $this->column = '__captcha__';
  14. $this->label = trans('admin.captcha');
  15. }
  16. public function setForm(Form $form = null)
  17. {
  18. $this->form = $form;
  19. $this->form->ignore($this->column);
  20. return $this;
  21. }
  22. public function render()
  23. {
  24. $this->script = <<<JS
  25. $('#{$this->column}-captcha').click(function () {
  26. $(this).attr('src', $(this).attr('src')+'?'+Math.random());
  27. });
  28. JS;
  29. return parent::render();
  30. }
  31. }