diff options
Diffstat (limited to 'pkg/tpl/add.templ')
-rw-r--r-- | pkg/tpl/add.templ | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/pkg/tpl/add.templ b/pkg/tpl/add.templ index 14b57eb..82d76e5 100644 --- a/pkg/tpl/add.templ +++ b/pkg/tpl/add.templ @@ -2,7 +2,10 @@ package tpl import "fmt" +var captchaHandler = templ.NewOnceHandle() + templ AddQuotePage(form *AddQuoteForm, err string) { + {{ captchaURL := fmt.Sprintf("/captcha/download/%s.png", form.CaptchaID) }} @Layout(HeaderParams{}) { <h2>Добавление цитаты</h2> if err != "" { @@ -14,10 +17,27 @@ templ AddQuotePage(form *AddQuoteForm, err string) { <form method="post"> <textarea rows="5" name="quote" placeholder="Текст цитаты">{ form.Quote }</textarea> <input type="hidden" name="captcha_id" value={ form.CaptchaID }/> - <img class="captcha" src={ fmt.Sprintf("/captcha/download/%s.png", form.CaptchaID) }/> - <input type="text" name="captcha_value" placeholder="Код с картинки"/> + <label for="captcha_value"> + <img class="captcha" id="captcha" src={ captchaURL }/> + <a + role="button" + data-url={ captchaURL } + onclick="reloadCaptcha(this)" + > + <i class="fa fa-refresh"></i> Обновить капчу + </a> + </label> + <input type="text" name="captcha_value" id="captcha_value" placeholder="Код с картинки"/> <input type="submit" value="Отправить на модерацию"/> </form> + @captchaHandler.Once() { + <script type="text/javascript"> + function reloadCaptcha(event) { + const url = event.getAttribute('data-url'); + document.getElementById('captcha').setAttribute('src', url+'?reload='+Math.random()); + } + </script> + } } } |