Written by: Geoffrey Callaghan
create a contact form with Sphinx
Create A Contact Form With Sphinx
To create a contact form in a Sphinx documentation site using FabForm, you’ll need to follow a few steps. Sphinx is a documentation generator, and FabForm is a form handling service. Here’s how to integrate a contact form into a Sphinx site using FabForm:
Set Up Sphinx Project:
pip install sphinx
sphinx-quickstart
Install a Theme (Optional):
pip install sphinx_rtd_theme
conf.py
to use the Read the Docs theme:
html_theme = 'sphinx_rtd_theme'
Create a Contact Page:
contact.rst
in your source directory:
.. _contact:
Contact Us
==========
.. raw:: html
<form action="https://fabform.io/f/YOUR_FORM_ID" method="POST">
<div>
<label for="name">Name:</label><br>
<input type="text" id="name" name="name" required><br>
</div>
<div>
<label for="email">Email:</label><br>
<input type="email" id="email" name="email" required><br>
</div>
<div>
<label for="message">Message:</label><br>
<textarea id="message" name="message" required></textarea><br>
</div>
<div>
<input type="submit" value="Submit">
</div>
</form>
Configure FabForm:
Update Table of Contents:
index.rst
or contents.rst
):
.. toctree::
:maxdepth: 2
:caption: Contents:
contact
Build Your Site:
make html
_build/html/index.html
in your web browser and navigate to the contact page to ensure your contact form appears correctly and can submit data.conf.py
):# Configuration file for the Sphinx documentation builder.
# -- Project information -----------------------------------------------------
project = 'My Project'
copyright = '2024, My Name'
author = 'My Name'
# -- General configuration ---------------------------------------------------
extensions = []
templates_path = ['_templates']
exclude_patterns = []
# -- Options for HTML output -------------------------------------------------
html_theme = 'sphinx_rtd_theme'
html_static_path = ['_static']
contact.rst
):.. _contact:
Contact Us
==========
.. raw:: html
<form action="https://fabform.io/f/YOUR_FORM_ID" method="POST">
<div>
<label for="name">Name:</label><br>
<input type="text" id="name" name="name" required><br>
</div>
<div>
<label for="email">Email:</label><br>
<input type="email" id="email" name="email" required><br>
</div>
<div>
<label for="message">Message:</label><br>
<textarea id="message" name="message" required></textarea><br>
</div>
<div>
<input type="submit" value="Submit">
</div>
</form>
index.rst
):.. My Project documentation master file, created by
sphinx-quickstart on Tue Jun 01 2024.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to My Project's documentation!
======================================
.. toctree::
:maxdepth: 2
:caption: Contents:
contact
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
By following these steps, you will have a fully functional contact form on your Sphinx site that integrates with FabForm for handling submissions.