Skip to main content

A library to create forms in aiogram3

Project description

aiogram3-form

A library to create forms in aiogram3

Example

# suppose you import here your router and bot objects
from aiogram import F, types

from aiogram3_form import Form, FormField


class NameForm(Form, router=your_router):
    first_name: str = FormField(enter_message_text="Enter your first name please")
    second_name: str = FormField(enter_message_text="Enter your second name please", filter=F.text.len() > 10)
    age: int = FormField(enter_message_text="Enter age as integer", error_message_text="Age should be numeric!")


@NameForm.submit()
async def name_form_submit_handler(form: NameForm, event_chat: types.Chat):
    # handle form data
    # also supports aiogram standart DI (e. g. middlewares, filters, etc)
    await bot.send_message(
        event_chat.id, f"Your full name is {form.first_name} {form.second_name}!"
    )
    
    
@router.message(F.text == "/form")
async def form_handler(message: types.Message, state: FSMContext):
    await NameForm.start(state)  # start your form

After submit callback call the state would be automatically cleared.

You can control this state using the following metaclass kwarg

...


class NameForm(Form, clear_state_on_submit=False):  # True by default
    ...


@NameForm.submit()
async def name_form_submit_handler(form: NameForm, state: FSMContext):
    # so you can set your exit state manually
    await state.set_state(...)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aiogram3_form-0.1.5.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

aiogram3_form-0.1.5-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file aiogram3_form-0.1.5.tar.gz.

File metadata

  • Download URL: aiogram3_form-0.1.5.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.0 CPython/3.10.8 Windows/10

File hashes

Hashes for aiogram3_form-0.1.5.tar.gz
Algorithm Hash digest
SHA256 ea2649fa82be601c27e7b425ed70a0c9f91b2c44f22bda3e62d4768fa10c3744
MD5 5b67d469ec88f1cbdf7f9efc461e2feb
BLAKE2b-256 73452933ef122c08d6aa70182dca1f06e4b945b98c1ffe0b5cffb3ac2f509e37

See more details on using hashes here.

File details

Details for the file aiogram3_form-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: aiogram3_form-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.0 CPython/3.10.8 Windows/10

File hashes

Hashes for aiogram3_form-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 1b741a818169a1b1299755c904a7708f88894135f7afa4d8ae7cdbc52d3409f3
MD5 5ae697f7a80cf69a555a26bb207c174c
BLAKE2b-256 e0a2de75cbf74c35239cfdb06fe213aa0faf911408c94a7577e376451c9f74c2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page