visual1au/statamic-phone-fieldtype 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

visual1au/statamic-phone-fieldtype

Composer 安装命令:

composer require visual1au/statamic-phone-fieldtype

包简介

A Statamic fieldtype for phone number validation and E.164 formatting using Laravel-Phone with Australia-first detection

README 文档

README

A Statamic fieldtype for phone number validation and E.164 formatting using Laravel-Phone. Perfect for forms and collections that need consistent phone number handling with Australia-first detection.

Features

  • Multi-format Input: Accepts various phone formats (0412 345 678, (07) 3210 1234, +61 412 345 678, +1 555 123 4567)
  • Australia-first Validation: Validates phone numbers using Laravel-Phone with Australia-first detection
  • E.164 Normalisation: Automatically converts valid numbers to E.164 format (e.g. +12345678901)
  • Form Compatible: Works in Statamic forms with custom validation messages
  • Integration Ready: Ensures consistent format for Zapier, HubSpot, and other integrations
  • User-Friendly: Clear error messages with international format examples

Installation

Install via Composer:

composer require visual1au/statamic-phone-fieldtype

Requirements

  • PHP 8.1+
  • Statamic 4.0+ or 5.0+
  • Laravel-Phone 5.0+ or 6.0+

The package automatically installs propaganistas/laravel-phone if not already present.

Configuration

Environment Variables

You can configure the phone number validation behavior using environment variables in your .env file:

# Set the primary country code (ISO 3166-1 alpha-2)
PHONE_FIELDTYPE_PRIMARY_COUNTRY=AU

# Enable/disable automatic fallback detection
PHONE_FIELDTYPE_AUTO_FALLBACK=true

Publishing Configuration

To customise the configuration, publish the config file:

php artisan vendor:publish --tag=phone-fieldtype-config

This will create config/phone-fieldtype.php where you can modify:

return [
    'primary_country' => env('PHONE_FIELDTYPE_PRIMARY_COUNTRY', 'AU'),
    'auto_fallback' => env('PHONE_FIELDTYPE_AUTO_FALLBACK', true),
];

Configuration Options

  • primary_country: The primary country code to use for validation (default: AU)
  • auto_fallback: Enable automatic fallback detection if primary country fails (default: true)

Usage

In Forms

Add the field to your form blueprint:

tabs:
  main:
    sections:
      -
        fields:
          -
            field:
              type: phone_number_field
              display: Phone Number
              validate:
                - required
              placeholder: 'e.g. 0412 345 678, +61 412 345 678, +1 555 123 4567'
            handle: phone_number

In Collections

Add to any collection blueprint:

tabs:
  main:
    sections:
      -
        fields:
          -
            field:
              type: phone_number_field
              display: Phone Number
              validate:
                - required
              placeholder: 'e.g. 0412 345 678'
            handle: phone_number

Configuration Options

The fieldtype supports standard text field options:

  • placeholder: Placeholder text
  • default: Default value
  • prepend: Text to prepend
  • append: Text to append

How It Works

  1. User Input: User enters phone number in various formats

    • 0412 345 678 (Australian mobile)
    • (07) 3210 1234 (Australian landline)
    • +61 412 345 678 (Australian international)
    • +1 555 123 4567 (International)
  2. Validation: Built-in validation with friendly error messages

    • Prioritises primary country format detection first (configurable, defaults to AU)
    • Falls back to international auto-detection (if enabled)
    • Shows clear error: "Please enter a valid phone number (e.g. 0412 345 678, (07) 3210 1234, +61 412 345 678, +1 555 123 4567)."
  3. Processing: Converts to E.164 format for storage

    • All formats → E.164 (e.g. +12345678901)
    • Consistent data for integrations
    • Maintains original input validation
  4. Integration: Perfect for external services

    • Zapier webhooks receive normalised format
    • HubSpot integration without format issues
    • API endpoints get consistent data structure

Example Data Flow

Input: 0412 345 678
↓ Validation (passes - detected as Australian)
↓ Processing
Output: +61412345678 (stored & sent to integrations)

Error Handling

Invalid inputs show user-friendly messages:

Input: 123
Error: "Please enter a valid phone number (e.g. 0412 345 678, (07) 3210 1234, +61 412 345 678, +1 555 123 4567)."

Development

To contribute or modify:

  1. Clone the repository
  2. Install dependencies: composer install
  3. Make changes to src/Fieldtypes/PhoneNumberField.php
  4. Test in a Statamic project

Changelog

1.0.0

  • Initial release
  • Phone number validation and E.164 formatting with Australia-first detection
  • Support for Australian local and international formats
  • Form and collection support
  • Custom validation messages

License

MIT License. See LICENSE for details.

Support

Credits

Built with:

visual1au/statamic-phone-fieldtype 适用场景与选型建议

visual1au/statamic-phone-fieldtype 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 102 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 09 月 17 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「validation」 「phone」 「fieldtype」 「statamic」 「E164」 「laravel-phone」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 visual1au/statamic-phone-fieldtype 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 visual1au/statamic-phone-fieldtype 我们能提供哪些服务?
定制开发 / 二次开发

基于 visual1au/statamic-phone-fieldtype 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 102
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 28
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-09-17