blob: 82d76e515b10adc742331ad10925863c4d8f00f4 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
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 != "" {
<article>
<header>Ошибка</header>
{ err }
</article>
}
<form method="post">
<textarea rows="5" name="quote" placeholder="Текст цитаты">{ form.Quote }</textarea>
<input type="hidden" name="captcha_id" value={ form.CaptchaID }/>
<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>
}
}
}
type AddQuoteForm struct {
Quote string `form:"quote"`
CaptchaID string `form:"captcha_id"`
CaptchaValue string `form:"captcha_value"`
}
|