CKAN forms usually import some macros located in ckan/templates/macros. Have a look at form.html and you'll get the idea. Also have a look at one of the examples (ckanext/example_idatasetform).
Basically you'd import the macros with {% import 'macros/form.html' as form %}
and then build the form with those macros, like this:
{% block package_basic_fields_custom %}
{{ form.input('custom_text', label=_('Custom Text'),
id='field-custom_text', placeholder=_('custom text'),
value=data.custom_text, error=errors.custom_text, classes= ['control-medium']) }}
{% endblock %}
AFAIK there's no special documention on how to create forms in CKAN. You should have a look at the relevant templates in ckan/templates/package