Phalcon 表单

17 Mar 2025 | 阅读 2 分钟

它处理 Web 应用程序中表单的创建和维护。现在,正如我们之前设计的 Web 应用程序一样,我们将添加注册表单。

设计注册表单

更改 index.phtml 视图文件,将注册页面链接添加为控制器。

app/views/index/index.phtml

输出

Phalcon Forms 1

现在,我们编写注册控制器

app/controllers/SignupController.php

初始化表单

在此表单中,我们提供表单定义,即提供表单的结构。

app/views/signup/index.phtml

输出

Phalcon Forms 2

验证表单

Phalcon 表单与验证组件集成,以提供即时验证。


表单元素

Phalcon 提供了一组内置元素,可在您的表单中使用。 所有这些元素都位于 Phalcon\Forms\Element. 中。

名称描述
Phalcon\Forms\Element\Text生成 INPUT[type=text] 元素
Phalcon\Forms\Element\Password生成 INPUT[type=password] 元素
Phalcon\Forms\Element\Select基于选项生成 SELECT 标签(组合列表)元素
Phalcon\Forms\Element\Check生成 INPUT[type=check] 元素
Phalcon\Forms\Element\TextArea生成 TEXTAREA 元素
Phalcon\Forms\Element\Hidden生成 INPUT[type=hidden] 元素
Phalcon\Forms\Element\File生成 INPUT[type=file] 元素
Phalcon\Forms\Element\Date生成 INPUT[type=date] 元素
Phalcon\Forms\Element\Numeric生成 INPUT[type=number] 元素
Phalcon\Forms\Element\Submit生成 INPUT[type=submit] 元素

下一主题Phalcon 图像