Skip to main content
This guide demonstrates how to build complete forms that interact with WordPress entity records using the data module. You’ll learn patterns for creating, editing, and deleting records with proper state management, error handling, and user feedback.

Edit Form Pattern

An edit form allows users to modify existing entity records. Here’s the complete pattern:

Key Edit Form Concepts

Use getEditedEntityRecord: Always use the edited version to reflect user changes:
Track Edit State: Use hasEditsForEntityRecord to disable save when unchanged:
Handle Async Saves: Check the promise result to close the form only on success:
The save operation returns the updated record on success, or undefined on failure. Never close the form modal before checking the result.

Create Form Pattern

A create form builds new entity records without a pre-existing ID:

Key Create Form Concepts

Use saveEntityRecord (not saveEditedEntityRecord):
Local State for Draft Data: Use React useState for fields since there’s no entity record yet:
No ID in Selectors: Omit the ID parameter when checking status:

Delete Operation Pattern

Delete Error Handling

Deletes can fail for many reasons:
  • Entity already deleted
  • User lacks permissions
  • Network errors
  • Invalid ID
Always check the result and provide feedback:

Reusable Form Component

Extract common form UI into a reusable component:
Then use it in both edit and create forms:

User Notifications

Use WordPress notices for user feedback:
Dispatch notifications from your forms:

Complete Example

Here’s a complete list view with create, edit, and delete:

Best Practices

Always Disable Actions During Operations

Provide Clear Visual Feedback

Use spinners during async operations:

Always Handle Errors

Prevent Form Closure on Errors

Only close the form modal when the operation succeeds:

Next Steps