表单示例
Baklib
发布于:2024-10-14
page- 页面表单
//创建帖子
{% form_tag 'page', method: 'post' %}
<input value="page" autocomplete="off" type="hidden" name="page[template_name]">
<input value="" autocomplete="off" type="hidden" name="page[template_style]">
<label for="title" class="block mb-1">标题</label>
<input type="text"
name="page[template_variables][title]"
value="{% if page.id %}{{ page.link_text }}{% endif %}"
class="form-input mt-1.5 w-full rounded-lg border "
placeholder="请输入内容标题" />
<textarea name="page[template_variables][content]" rows="8" class="w-full form-textarea placeholder:italic" placeholder="问题详情"> {{ content }}</textarea>
<button type="submit" class="py-2 rounded cursor-pointer bg-primary">{{ submit_value | default: '创建帖 子' }}</button>
{% endform_tag %}
//编辑帖子
{% form_tag 'page', page, method: 'patch' %}
<input value="post" autocomplete="off" type="hidden" name="page[template_name]">
<input value="" autocomplete="off" type="hidden" name="page[template_style]">
<label for="title" class="block mb-1">标题</label>
<input type="text"
name="page[template_variables][title]"
value="{% if page.id %}{{ page.link_text }}{% endif %}"
class="form-input mt-1.5 w-full rounded-lg border "
placeholder="请输入内容标题" />
<textarea name="page[template_variables][content]" rows="8" class="w-full form-textarea placeholder:italic" placeholder="问题详情"> {{ content }}</textarea>
<button type="submit" class="py-2 rounded cursor-pointer bg-primary">{{ submit_value | default: '创建帖 子' }}</button>
{% endform_tag %}//删除帖子
{% form_tag 'page', page, method: 'delete' %}
<button class="inline px-4 py-2 text-gray-700"> 删除 </button>
{% endform_tag %}
reply- 页面表单
//创建评论
{% form_tag 'reply' %}
<input value="{{ root.target.path }}" autocomplete="off" type="hidden" name="target_full_path">
<input value="create_answer_reply_success" autocomplete="off" type="hidden" name="return_template_name">
<input value="true" autocomplete="off" type="hidden" name="reply[published]">
<input value="{{ root.id }}" autocomplete="off" type="hidden" name="reply[root_id]">
<input value="{{ parent.id }}" autocomplete="off" type="hidden" name="reply[parent_id]">
<textarea name="reply[body]" rows="4" class="w-full form-textarea placeholder:italic"
placeholder="回复{{ parent.author.name }}..." ></textarea>
<input type="submit" value="提交" @click="open = false;name=content.substring(0, 50)" class="inline-flex items-center justify-center px-4 py-1 mt-2 text-xs font-medium leading-5 transition duration-150 ease-in-out rounded-full bg-primary whitespace-nowrap" />
{% endform_tag %}//删除评论
{% form_tag 'reply', reply, method: 'delete' %}
<input value="destroy_reply_success" autocomplete="off" type="hidden" name="return_template_name">
<button class="inline"> 删除 </button>
{% endform_tag %}
richtext_field_tag-富文本内容输入框
{% richtext_field_tag 'page[template_variables][content]', content, toolbar: 'full' %}