Trongate PHP Framework Docs
Introduction
Basic Concepts
Understanding Routing
Intercepting Requests
Module Fundamentals
Database Operations
Templates
Helpers
Form Handling
Form Validation
Working With Files
Image Manipulation
Working With Dates & Times
Language Control
Authorization & Authentication
Tips And Best Practices

Week Input Fields

The week input field allows users to select a week and year. It provides a user-friendly week picker and submits data in YYYY-W## format using ISO 8601 week numbering.

Browser Display vs Submitted Format: Browsers display weeks according to user locale, but always submit in consistent ISO 8601 format (YYYY-W##) that your PHP code can rely on.

Basic Usage

Use to create a week input field:

Demonstration

Below is the native HTML5 week input rendered by form_week():

Function Signature

Parameters

Parameter Type Description Default
$name string The name attribute for the input (required) N/A
$value string|null The value in YYYY-W## format null
$attributes array Additional HTML attributes []

With a Default Value

Setting Current Week as Default

Zero-Padding Required: Week numbers must be zero-padded: W01 not W1. Always use str_pad(date('W'), 2, '0', STR_PAD_LEFT) to ensure proper formatting.

With Attributes

Output:

Boolean Attributes: Pass true for boolean attributes like required, readonly, or disabled. This generates clean HTML5 syntax: <input required>

Downloadable Demo: Want to see the function in action? Why not head over to GitHub and check out the complete Weekly Schedules demo module:

https://github.com/trongate/Trongate-v2-Weekly-Schedules-Module

This repository provides a ready-to-use example of building a weekly scheduling system using the Trongate PHP framework (version 2). It includes pagination, form validation, secure admin access, native HTML5 week input handling, and clean separation of concerns.

Common Attributes

Attribute Purpose Example
min Earliest selectable week (YYYY-W##) ['min' => '2025-W01']
max Latest selectable week (YYYY-W##) ['max' => '2025-W52']
required Field must have a value ['required' => true]
readonly Prevent user editing ['readonly' => true]
disabled Disable the input ['disabled' => true]

Understanding ISO 8601 Week Numbering

Week inputs follow the ISO 8601 international standard for week numbering. Understanding these rules is important:

ISO 8601 Week Rules:

  • Weeks start on Monday (not Sunday)
  • Week 1 is the first week that contains a Thursday in the new year
  • This means January 1st might be in week 52 or 53 of the previous year
  • A year can have 52 or 53 weeks

Example of Week 1 Determination

How to Repopulate Forms After Validation Errors

Controller Example

View Example

Form Repopulation Pattern: Always use post('field_name', true) in the controller to fetch submitted values. The true parameter trims whitespace, ensuring clean data.

Real-World Example: Weekly Timesheet

Controller:

View:

Working with the Create/Update Pattern

Type-Casting Segments: Always use segment(3, 'int') when expecting numeric IDs. This prevents type-related bugs and improves code clarity.

Database Storage

Week inputs submit in YYYY-W## format, which can be stored directly in a VARCHAR column:

Table Schema

Inserting Data

Direct Storage: The YYYY-W## format from HTML5 week inputs can be stored directly in a VARCHAR(8) column. No conversion is needed, and the data remains human-readable.

Converting Week to Date Range

To query data for a specific week, you'll often need to convert to a date range:

Querying by Week

Query by Stored Week Value

Query by Date Range

Formatting Weeks for Display

When displaying weeks to users, you'll often want to format them in a more readable way:

Validation

Use the valid_week validation rule to ensure the submitted value is in the correct format:

This validates that the value matches YYYY-W## format and represents a valid week.

Client vs Server Validation: While browsers validate week formats client-side, always use server-side validation with valid_week. Client validation can be bypassed and doesn't protect your database.

See the Validating Date and Time Data chapter for complete validation rule documentation.

Restricting Week Selection

Current Year Only

Past 4 Weeks

Specific Week Range

Common Use Cases

  • Timesheets - Weekly hour tracking and time entry
  • Production planning - Weekly manufacturing schedules and capacity planning
  • Sales targets - Weekly sales goals, quotas, and performance tracking
  • Project management - Sprint planning (typically 1-2 week sprints)
  • Staff scheduling - Weekly work rosters and shift planning
  • Delivery schedules - Weekly shipping plans and logistics
  • Weekly reports - Status reports, KPIs, and performance metrics
  • Appointment scheduling - Weekly availability and booking slots

Browser Support and Rendering

Different browsers provide different week picker interfaces:

  • Chrome/Edge: Calendar view with week numbers highlighted
  • Firefox: Week and year input fields with increment/decrement controls
  • Safari: Limited support - may render as text input
  • Mobile (iOS/Android): Native week picker where supported

Safari Limitation: Week input support is limited in Safari. It may render as a plain text input. Users can still manually enter values in YYYY-W## format (e.g., "2025-W52"), and validation will work correctly. Consider adding helper text for Safari users.

Providing Helper Text

Important Notes

  • Value format is always YYYY-W## with zero-padded week number
  • Store as VARCHAR(8) in database
  • No conversion needed between form and database
  • Week numbers follow ISO 8601 standard (weeks start Monday)
  • Always use str_pad() for week numbers to ensure zero-padding
  • January 1st may be in week 52 or 53 of the previous year
  • Safari support is limited - may fallback to text input
  • Browser validates format automatically, but server validation is still required

Value Format: The value attribute must be in YYYY-W## format with zero-padded week numbers. Values like 2025-W5 (missing zero) or 2025/W52 (wrong separator) will not work and the field will appear empty.