ShOrgRu/pkg/tpl/add.templ
Alexander Neonxp Kiryukhin e849e705c3
Добавил рейтинг
Добавил страницу топа
Добавил rss/xml/json feed
2024-10-08 03:50:53 +03:00

49 lines
1.4 KiB
Text
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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>&nbsp;Обновить капчу
</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"`
}