Skip to content

File Upload

A file upload field that handles file selection, validation, and upload to the WordPress media library. Returns the uploaded file's URL.

Properties

PropertyTypeDefaultDescription
nametext''The field name. The uploaded file URL is stored under this key.
labeltext''The visible label displayed above the upload area.
accepttext''Allowed MIME types, comma-separated (e.g., image/*, application/pdf). Empty allows all types.
maxSizeMbnumber5Maximum file size in megabytes.
requiredbooleanfalseWhether a file must be uploaded for form submission.

Events

  • onChange -- Fires when a file is selected or uploaded.

Example

An image upload:

name: photo
label: Upload Photo
accept: image/*
maxSizeMb: 10
required: true

A document upload:

name: resume
label: Upload Resume
accept: application/pdf,.doc,.docx
maxSizeMb: 5
required: true

Tips

  • Place inside a Form Container for the uploaded file URL to be included in form submissions.
  • The uploaded file goes through WordPress's wp_handle_upload() function, which applies all standard WordPress security checks.
  • The accept property restricts file selection in the browser's file picker. Always validate server-side too -- clients can bypass browser restrictions.
  • After a successful upload, the field value becomes the file's WordPress media library URL (e.g., https://example.com/wp-content/uploads/2024/01/photo.jpg).
  • Use the Image widget with src: { {row.photo}} to display previously uploaded images.
  • For security, restrict accept to only the MIME types your app actually needs.