This example demonstrates how to create a simple web application that collects user input through an HTML form and submits it to a Notion database using the notion-sdk-php.
The application uses the Slim Framework for routing and Twig for templating, providing a complete example of integrating Notion into a web context.
- PHP 7.4 or higher with built-in web server support
- Composer
- Notion Integration Token
- Notion Database with the following properties:
- Name (Title)
- Email (Email)
- Message (Text)
Navigate to this directory and install the required packages using Composer:
cd examples/03-web-form
composer installCreate a .env file by copying the example file:
cp .env.example .envOpen the .env file and add your Notion integration token and database ID:
NOTION_TOKEN="secret_..."
NOTION_DATABASE_ID="..."Start the built-in PHP web server:
composer serveOpen your browser and navigate to http://localhost:8000. You'll see a form where you can enter:
- Name: Your full name
- Email: Your email address
- Message: Any message or feedback
When you submit the form, a new page will be created in your Notion database with the provided information.
index.php- Application entry point and routingFormHandler.php- Business logic for Notion integrationtemplates/- Twig templates for the form and success pageform.html- Main form templatesuccess.html- Success confirmation page
- Clean, responsive form design
- Input validation with error messages
- Success confirmation with link to created page
- Graceful error handling for API failures
- Automatic property detection in Notion database